WTF Solution

Display Multiple Copies of Smartform in SAP ABAP

In SAP ABAP, if you want to print/ display multiple copies of smartform the same form (for example, Original, Duplicate, Triplicate, etc.), you can handle it using control parameters or Smartform output options. Below, you need to follow some steps.

Multiple Copies of SmartForm

Step 1: Get the SmartForm FM name

Here, we are using the SSF_FUNCTION_MODULE_NAME function module to get the SmartForm FM name (Function Module name) from the SmartForm name. That function module is helping to call the form.

DATA: JOB_OUTPUT_INFO    TYPE SSFCRESCL,
        CONTROL_PARAMETERS TYPE SSFCTRLOP,
        OUTPUT_OPTIONS      TYPE SSFCOMPOP,
LV_FM_NAME TYPE RS38L_FNAM.

" Get Smartform FM name
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME         = 'ZRP_SF1' ""ZRP_SF1 is the SmartForm Name
  IMPORTING
    FM_NAME            = LV_FM_NAME
  EXCEPTIONS
    NO_FORM            = 1
    NO_FUNCTION_MODULE = 2
    OTHERS              = 3.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Step 2: Set Control Parameters (Like preview, no_dialog)

" Set control parameters
CONTROL_PARAMETERS-PREVIEW = 'X'.
CONTROL_PARAMETERS-NO_DIALOG = 'X'.
CONTROL_PARAMETERS-NO_OPEN = 'X'.
CONTROL_PARAMETERS-NO_CLOSE = 'X'.

CALL FUNCTION 'SSF_OPEN'
 EXPORTING
   CONTROL_PARAMETERS = CONTROL_PARAMETERS
EXCEPTIONS
   FORMATTING_ERROR   = 1
   INTERNAL_ERROR     = 2
   SEND_ERROR          = 3
   USER_CANCELED      = 4
   OTHERS              = 5  .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Step 3: Call the SmartForm with Loop for Multiple copies of SmartForm

Here, we store the Original, Duplicate, and Triplicate text values into the table and call the form.

DATA: lt_copies TYPE STANDARD TABLE OF string,
lv_copy TYPE string.

lt_copies = VALUE #( ( 'ORIGINAL' ) ( 'DUPLICATE' ) ( 'TRIPLICATE' ) ).

LOOP AT lt_copies INTO lv_copy.
WA_HEADER-PTEXT = lv_copy.

" Call Smartform
CALL FUNCTION LV_FM_NAME "'/1BCDWB/SF00000144'
  EXPORTING
CONTROL_PARAMETERS = CONTROL_PARAMETERS
OUTPUT_OPTIONS      = OUTPUT_OPTIONS
WA_HEADER          = WA_HEADER
IT_ITEM            = IT_ITEM
EXCEPTIONS
    FORMATTING_ERROR   = 1
    INTERNAL_ERROR      = 2
    SEND_ERROR          = 3
    USER_CANCELED      = 4
    OTHERS             = 5.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDLOOP.

CALL FUNCTION 'SSF_CLOSE'
 IMPORTING
   JOB_OUTPUT_INFO        = JOB_OUTPUT_INFO
 EXCEPTIONS
   FORMATTING_ERROR    = 1
   INTERNAL_ERROR         = 2
   SEND_ERROR              = 3
   OTHERS                  = 4      .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Related blog.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top