Home > ABAP, Forms > Smartforms – a simple example

Smartforms – a simple example

December 7th, 2009 Leave a comment Go to comments

If we need to print the ALV report out with certain font size and some decorate requirement, I think we need to utilize smartform to achieve this. I recorded some important steps in this post.

1. Create a new GUI status.
A new GUI status is needed as I need to a button in the toolbar to support print ALV out. You can copy the standard ALV GUI status out and add a new function code like ‘Print’ or something like that.

gui_status

Standard GUI status locates in program ‘SAPLKKBL‘ and with name ‘STANDARD_FULLSCREEN‘.

2. Create the smartform using tcode ‘SMARTFORMS’.

smartform

In the most common case, for each smartform, we maintain a corresponding style. For how to create smartform, please refer below links from SAP help portal.

http://help.sap.com/saphelp_nw04/helpdata/EN/1c/f40c6fddf311d3b574006094192fe3/frameset.htm

3. Integrate the report and the smartform.

After creating the smartform, a few code need to added to report to trigger the print of the smartform. If user choose ‘Print’ button, the content of the report should be outputted using smartform. Below is the code.

FORM user_command USING r_ucomm     LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield.
 
  DATA: lv_fm_name TYPE rs38l_fnam.
 
  CASE r_ucomm.
    WHEN 'PRINT'.
 
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname                 = gc_rss_line_le
        IMPORTING
          fm_name                  = lv_fm_name
        EXCEPTIONS
          no_form                  = 1
          no_function_module       = 2
          OTHERS                   = 3.
 
*   build the print parameter
      gs_control-device    = 'PRINTER'.
      gs_control-langu     = 'E'.
*     gs_control-no_dialog = gc_charx.
 
      gs_options-tdimmed   = gc_charx.
 
*     Call smartform
      CALL FUNCTION lv_fm_name
        EXPORTING
          user_settings      = space
          control_parameters = gs_control
          output_options     = gs_options
        TABLES
          it_rss_line        = gt_output
        EXCEPTIONS
          formatting_error   = 1
          internal_error     = 2
          send_error         = 3
          user_canceled      = 4
          OTHERS             = 5.
 
    WHEN OTHERS.
  ENDCASE.
 
ENDFORM.                               " user_command

After finishing above three steps, everything should be ready. Is it quite simple and easy?

  1. arun
    July 7th, 2011 at 20:04 | #1

    how to make print button in alv grid to trigger smartform form?
    ,

  2. July 7th, 2011 at 20:41 | #2

    Hi There,

    I think you can add your custom button on the standard gui status for ALV and handle the function code in your program to trigger the smartform printing.

    Regards,
    Andy

  1. No trackbacks yet.