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

To Print Multiple Smartform in a Loop at one Go and

converting into PDF



Posted by Kumar Saurabh in ABAP Development on Apr 22, 2013 3:35:05 PM
inShare5
I ntroduction:-
In this Document we will explain how to display multiple smartfforms in a loop at one go.
There are Scenario when user has to Print multiple smartform in a loop. The problem with this is that if you will write the
following code.
Fig 1.

Print window(Shown in fig below) will come multiple time. If hundreds of lines are present in the table it is very tough to
see one by one and even tougher if you have to save all the smartforms into PDF.

Print Window.
Fig 2.


There is a way to Print all the smartforms in one go, so that the Pint window(above) does not comes multiple times and
all the smartforms will get displayed in one output on different pages.
Step 1. Use function module SSF_FUNCTION_MODULE_NAME to retrieve the name of the function module generated
from the Smart Form.
Step 2. Call the Smart Form for the first time and set the NO_CLOSE parameter of the control structure. This prevents the
print request from being closed after accepting the output of the Smart Form and allows you to include all other form
output into this print request as well. Leave the NO_OPEN parameter empty.
Step 3. For all other form output of the application program that you want to include into the print request, use a loop to
set both the NO_OPEN field and the NO_CLOSE field of the control structure.
Step 4. To close the print request, in the call of the last Smart Form set the NO_OPEN parameter and unmark the
NO_CLOSE parameter

All these steps are shown in the following steps of coding.



data:
control_parameters type ssfctrlop,
w_cnt type I,
w_cnt2 type I,
fname type rs38l_fnam.

call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'ZCUSTOMER_LEDGER' " Smart program has same
" name as of driver program
importing
fm_name = fname
exceptions
no_form = 1
no_function_module = 2
others = 3.
if sy-subrc <> 0.
message 'Wrong Smartform Name' type 'E'.
endif.
************************** CHANGE FROM HERE


describe table it_tab lines w_cnt.

loop at it_tab into st_tab.
w_cnt2 = sy-tabix .
case w_cnt2.
when 1.
control_parameters-no_open = space .
control_parameters-no_close = 'X' .
when w_cnt .
control_parameters-no_open = 'X' .
control_parameters-no_close = space .
when others.
control_parameters-no_open = 'X' .
control_parameters-no_close = 'X' .
endcase.


call function fname
exporting
control_parameters = control_parameters
w_kunnr = st_tab-kunnr
w_bukrs = p_bukrs
w_bdat_l = s_budat-low
w_bdat_h = s_budat-high
zcus_ledg_st = st_tab
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
exceptions
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
others = 5
.
if sy-subrc <> 0.
message 'ERROR RELATED TO SMARTFORM OR PAGE FORMAT OR PRINTER' type 'E'.
endif.
endloop.


Note:-NO_OPEN AND NO_CLOSE parameter of CONTROL_PARAMETERS are used to include
several forms into one print request. When calling the generated functions modules, set the parameters as follows:
1st call: NO_OPEN = SPACE.
NO_CLOSE = 'X'.
nth call: NO_OPEN = 'X'.
NO_CLOSE = 'X'.
last call: NO_OPEN = 'X'.
NO_CLOSE = SPACE .
After doing this when you run the smart form, Print window will come only once and all the smartforms will come in
single output in different pages. See the fig below, different Smartforms(i.e. 7 here) are coming on diff pages. Keep on
pressing PAGE DOWN and you will keep on getting diff Smartforms.
To convert all this into PDF Write PDF! On the command field of smartforms output and all these smartforms will get
converted into PDF.

Fig 3.

To convert all the Smartforms into PDF at one go.

In SmartForm Output write PDF! on Command Field.

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