
Executing a SmartForm
To execute a Smartform, we need to run the form printing program. Every printing program follows similar steps:
- Data retrieval and loading into one or more internal tables.
- Retrieve the function module name that executes the form using the SSF_FUNCTION_MODULE_NAME function.
- Execute the function module whose name we retrieved in the previous step.
- Configure the form's print screen. Various aspects can be informed here:
-
Form title.
-
Direct execution of printing without passing through the spool first.
-
Determination of the number of copies to print.
-
Storage Mode allows determining whether we only print or also save the print in the spool.
-
In Cover Page Settings, we can decide whether to print the SAP cover page on the same sheet.
-
Mandatory printer output notification even if a preview is performed.
*&---------------------------------------------------------------------*
*& Form INVOCAR_SMARTFORM
*&---------------------------------------------------------------------*
* Inicializar a imprimir smartform
*----------------------------------------------------------------------*
FORM invocar_smartform .
IF NOT ti_usuarios[] IS INITIAL.
* Inicializar el formulario.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZFORMULARIO_PRUEBA'
IMPORTING
fm_name = v_nombre_form
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Enviar datos al formulario e imprimirlo
CALL FUNCTION v_nombre_form
TABLES
ti_usuarios = ti_usuarios
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDFORM. " INVOCAR_SMARTFORM
Debugging a SmartForm
We go to the Smartforms transaction, enter the form name, and click the modify button.
We create a code lines object in the desired page's first window. The code will be the breakpoint statement, and we activate the form. Upon re-executing the form, it will stop where we placed the breakpoint.
Alternatively, we can execute the transaction SMARTFORM_TRACE. In the selection screen, we activate tracing by clicking the activate button and set the trace level. The following levels are available:
- Warning or error.
- Document information.
- Pages.
- Windows.
Then, we inform the form printing program. Once the form is displayed, we return to the SMARTFORM_TRACE transaction, search for the trace of our execution, and upon entering it, we will see all detected errors.
E.g
*&---------------------------------------------------------------------*
*& Report ZTEST_ABAP_JEGA_I_1
*&---------------------------------------------------------------------*
*& Ejemplo smartform program
*&---------------------------------------------------------------------*
REPORT ztest_abap_jega_i_1.
* Nombre del modulo de funciones del formulario.
DATA: v_nombre_form(30) TYPE c.
DATA: ti_usuarios TYPE STANDARD TABLE OF zusuarios.
*Previamente creamos en el Diccionario de datos la estructura ZUSUARIOS
*con los mismos campos de ZTABLA_USUARIOS a excepción del Mandante
* ---------------------------------------------------------------------*
START-OF-SELECTION.
* ---------------------------------------------------------------------*
* Seleccionamos los datos de la tabla de usuarios
PERFORM cargar_datos.
* Llamada al formulario Smartform
PERFORM invocar_smartform.
*&---------------------------------------------------------------------*
*& Form CARGAR_DATOS
*&---------------------------------------------------------------------*
* cargar datos en la tabla interna
*----------------------------------------------------------------------*
FORM cargar_datos .
CLEAR ti_usuarios.
REFRESH ti_usuarios.
SELECT dni nombre_ape estado_usu direccion
FROM ztabla_usuarios
INTO CORRESPONDING FIELDS OF TABLE ti_usuarios.
ENDFORM. " CARGAR_DATOS
*&---------------------------------------------------------------------*
*& Form INVOCAR_SMARTFORM
*&---------------------------------------------------------------------*
* Inicializar a imprimir smartform
*----------------------------------------------------------------------*
FORM invocar_smartform .
IF NOT ti_usuarios[] IS INITIAL.
* Inicializar el formulario.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZFORMULARIO_PRUEBA'
IMPORTING
fm_name = v_nombre_form
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Enviar datos al formulario e imprimirlo
CALL FUNCTION v_nombre_form
TABLES
ti_usuarios = ti_usuarios
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDFORM. " INVOCAR_SMARTFORM