Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
amy_king
Active Contributor
4,565

Overview


The Smart Form copies window is a useful feature that can be used to print a Smart Form in duplicate, triplicate, etc. while distinguishing a copy from the original or distinguishing one copy from another copy, e.g., when one copy is the customer copy and the original is the office copy.

Extra processing steps are needed to generate a single PDF document which combines these copies.

By using the copynumber parameter available in the interface of function module CONVERT_OTF since SAP_BASIS 620 along with utility class CL_RSPO_PDF_MERGE introduced in SAP_BASIS 731, we can retrieve all Smart Form copies and merge them into a single PDF document.

N.B., the code samples below use new ABAP syntax introduced in SAP_BASIS 740. If you are at a lower release, you can rework these statements to achieve the same result.

Step 1: Instantiate the PDF Utility


DATA(lo_pdf_helper) = NEW cl_rspo_pdf_merge( ).

Step 2: Generate Smart Form Output


DATA fm_name TYPE rs38l_fnam.
DATA job_output_info TYPE ssfcrescl.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'MY_SMARTFORM'
IMPORTING
fm_name = fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.

DATA(control_parameters) = VALUE ssfctrlop( getotf = abap_true
no_dialog = abap_true ).

DATA(output_options) = VALUE ssfcompop( tdcopies = 3 ). " however many copies are needed

CALL FUNCTION fm_name
EXPORTING
control_parameters = control_parameters
output_options = output_options
... = ...
IMPORTING
job_output_info = job_output_info
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.

Step 3: Convert OTF Data of Each Copy and Collect into the PDF Utility


DATA bin_file TYPE xstring
DATA lines TYPE tline_tab.

DO output_options-tdcopies TIMES.

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
copynumber = CONV rspocopies( sy-index )
IMPORTING
bin_file = bin_file
TABLES
otf = job_output_info-otfdata[]
lines = lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.

IF sy-subrc IS INITIAL.
lo_pdf_helper->add_document( bin_file ).
ENDIF.

ENDDO. " output_options-tdcopies

Step 4: Merge Individual PDF Documents


lo_pdf_helper->merge_documents( 
IMPORTING
merged_document = DATA(merged_document)
).

Step 5: Proceed According to Your Application's Needs


In this example, we download the merged PDF to the local file system.
DATA bin_tab TYPE ty_xline_tabtype.
DATA filename TYPE string.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = merged_document
TABLES
binary_tab = bin_tab.

DATA(lo_gui) = NEW cl_gui_frontend_services( ).

lo_gui->gui_download(
EXPORTING
filename = filename
filetype = 'BIN'
CHANGING
data_tab = bin_tab
).
2 Comments
Labels in this area