Skip to Content

Introduction:-

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.

To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

  1. MUTHURAJA PERIYASAMY

    Dear all,

    I want to print multiple employee details one bye one in smartform..

    I followed this code…

    1)   I dont know how to use the  control_parameters..

         This code working but i didnt get the print preview screen…

    2) How to pass the table values in function module and how to use it in smartform

    This is my code.

    REPORT  zemployee_print.

    DATA : fm_name TYPE rs38l_fnam. ” Name of the Function Module

    TYPES: BEGIN OF temp,

            e_id TYPE zemployee-empid,

            name TYPE zemployee-empname,

            dob TYPE zemployee-dob,

            desi TYPE zemployee-desi,

            basic TYPE zemployee-basicpay,

            hra TYPE zemployee-hra,

            others TYPE zemployee-others,

            tax TYPE zemployee-tax,

            END OF temp.

    DATA: zemp type standard table of temp,

          wa_zemp type temp,

          wa_temp type temp.

    DATA: gross_pay type zemployee-basicpay,

          net_pay type zemployee-basicpay,

          control_parameters  type ssfctrlop,

          w_cnt type I,

        w_cnt2 type I.

    *————– START OF SELECTION SCREEN Design—————————-*

    SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

    PARAMETERS: VALUE1 LIKE zemployee-empid OBLIGATORY,

                 VALUE2 LIKE zemployee-empid OBLIGATORY.

    SELECTION-SCREEN: END OF BLOCK b1.

    *————– END OF SELECTION SCREEN Design——————————*

    SELECT empid empname dob desi basicpay hra others tax FROM

    zemployee INTO TABLE zemp WHERE empid BETWEEN VALUE1 AND VALUE2.

    field-symbols : <empid> type empid.

    LOOP AT zemp INTO wa_zemp.

      wa_temp = wa_zemp.

    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.

    *…………….. Calculation….*

    gross_pay = wa_temp-basic + wa_temp-hra + wa_temp-others.

    net_pay = gross_pay – wa_temp-tax.

    *…………….. Calling the fiuncion module…………..*

    CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’

      EXPORTING

        formname           = ‘ZTEST2’ ” Pass the smartform Name

      IMPORTING

        fm_name            = fm_name ” Name of Function Module

      EXCEPTIONS

        no_form            = 1

        no_function_module = 2

        OTHERS             = 3.

    IF sy-subrc <> 0.

    ENDIF.

    CALL FUNCTION fm_name

      EXPORTING

    control_parameters         = control_parameters

        eid = wa_temp-e_id

        name = wa_temp-name

        dob = wa_temp-dob

        desi = wa_temp-desi

        basic = wa_temp-basic

        hra =  wa_temp-hra

        others =  wa_temp-others

        tax =  wa_temp-tax

        grosspay = gross_pay

        netpay = net_pay

      EXCEPTIONS

        formatting_error = 1

        internal_error   = 2

        send_error       = 3

        user_canceled    = 4

        OTHERS           = 5.

      IF sy-subrc <> 0.

      MESSAGE s000(zsd_inv).

      ENDIF.

      ENDLOOP.

    (0) 
  2. sureshraj muthukrishnan

    Hi , Thank you very much for your idea ,i can able to see the print preview of multiple pages .

    but when try to come back ,its going to previous print Dialog box ,it is direcgtly exiting from the

    program. when i press back it should go print dialog box.please guide what should i do for this.

     

    Thanks in advance.

    Sureshraj.M

    (0) 

Leave a Reply