Difference between revisions of "SAP ABAP SMARTFORMS"

From SapWiki
Line 510: Line 510:
  
 
  <nowiki>
 
  <nowiki>
* <CB><&TIMBRE+1(250)&&TIMBRE+250(250)&&TIMBRE+500(250)&
+
* <CB><&TIMBRE+1(250)&&TIMBRE+251(250)&&TIMBRE+501(250)&
= &TIMBRE+750(250)&&TIMBRE+1000(250)&&TIMBRE+1250(250)&</>
+
= &TIMBRE+751(250)&&TIMBRE+1001(250)&&TIMBRE+1251(250)&</>
 
</nowiki>
 
</nowiki>

Revision as of 22:28, 14 April 2020

Ejemplo de función que retorna smartform en BASE 64 con preview para pruebas en la trn. SE37

FUNCTION zhr_get_pdf.
*"----------------------------------------------------------------------
*"*"Interfase local
*"  IMPORTING
*"     VALUE(P_PERNR) TYPE  PERNR_D OPTIONAL
*"     VALUE(P_IDDOCUMENTO) TYPE  TIM_REQ_ID OPTIONAL
*"  EXPORTING
*"     VALUE(P_BINFILE) TYPE  XSTRING
*"     VALUE(P_FILEBASE64) TYPE  STRING
*"     VALUE(P_ERRMSG) TYPE  STRING
*"----------------------------------------------------------------------
  DATA: lt_otf             TYPE TABLE OF itcoo,
        lt_pdfdata         TYPE TABLE OF tline,
        ls_control_param   TYPE ssfctrlop,
        ls_composer_param  TYPE ssfcompop,
        ls_job_output_info TYPE ssfcrescl,
        l_formname         TYPE tdsfname VALUE 'ZSF_MY_SMARTFORM',
        l_fm_name          TYPE rs38l_fnam,
        l_bin_file         TYPE xstring.

  DATA wa_data TYPE kna1.  "only for example

*insert some logic here

*--------------------------------------------------------------------*
* call Smartform
*--------------------------------------------------------------------*
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = l_formname
    IMPORTING
      fm_name            = l_fm_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO p_errmsg.
    RETURN.
  ENDIF.

  ls_control_param-device = 'PRINTER'.
  ls_control_param-no_dialog = 'X'.
  ls_control_param-preview   = ''.
  ls_control_param-no_open   = ''.
  ls_composer_param-tdcover  = ' '.
  ls_control_param-getotf    = 'X'.
  ls_composer_param-tdimmed  = 'X'.
  ls_composer_param-tdcopies = 1.

  CALL FUNCTION l_fm_name
    EXPORTING
      control_parameters = ls_control_param
      output_options     = ls_composer_param
      i_data             = wa_data
    IMPORTING
      job_output_info    = ls_job_output_info
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.
  IF sy-subrc <> 0.
* Implement suitable error handling here
*     Transfer SF errors to internal table
    DATA lt_errortab TYPE tsferror.

    CALL FUNCTION 'SSF_READ_ERRORS'
      IMPORTING
        errortab = lt_errortab.

    LOOP AT lt_errortab INTO DATA(wa).
      MESSAGE ID wa-msgid TYPE wa-msgty NUMBER wa-msgno
            WITH wa-msgv1 wa-msgv2 wa-msgv3 wa-msgv4 INTO p_errmsg.
      EXIT.
    ENDLOOP.
    RETURN.
  ENDIF.

  lt_otf[]  = ls_job_output_info-otfdata[].
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
    IMPORTING
      bin_file              = l_bin_file
    TABLES
      otf                   = lt_otf
      lines                 = lt_pdfdata
    EXCEPTIONS ##FM_SUBRC_OK
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      OTHERS                = 4.

  IF NOT l_bin_file IS INITIAL.
    p_binfile = l_bin_file.
  ENDIF.

  CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
    EXPORTING
      input  = p_binfile
    IMPORTING
      output = p_filebase64.

  IF sy-tcode = 'SE37'.
*  Preview PDF.
    CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
      EXPORTING
        i_otf                    = lt_otf[]
      EXCEPTIONS ##fm_subrc_ok
        convert_otf_to_pdf_error = 1
        cntl_error               = 2
        OTHERS                   = 3.
  ENDIF.

ENDFUNCTION.

Problema de generación de smartform despues de un transporte

Ver Nota: SAP Note 630105 - Generating Smart Forms after transport

Solution

If you want to generate the transported Smart Forms before the first call in the target system, create report RSTXGALL in the system. You can then run RSTXGALL after a transport if required.

report rstxgall.
data: form type tdsfname,
forms type table of tdsfname.
select formname from stxfadm into table forms
where formtype = space.
loop at forms into form.
  call function 'SSF_FUNCTION_MODULE_NAME'
  exporting
    formname = form
  exceptions
    others = 1.
endloop.

Incluir un texto estandard(sapscript) en un formulario smartform

Si se desea utilizar un texto estandard(SO10) como un texto include, y este posee un estilo X(SE72), este estilo X debe crearse como smartstyle con los mismos parrafos y caracteres.

Fondo gris en imagenes (logos)

Si al cargar una imagen en la SE78 y en vez de verse el color blanco original se ve un gris leve, esto es porque sap admite imágenes de hasta 256 colores, entonces una solución es grabar la imagen como BMP de 256 colores con el PAINT de Windows u otro editor de imágenes, aunque pierde resolución (ver nota SAP 205837)

Activar/desactivar editor microsoft Office

ver reporte RSCPSETEDITOR

Activar trace smartform

transaccion SFTRACE

Traducción de SMARTFORMS

Ir a SE63, Translation-->R/3 Enterprise-->Other Long Texts, seleccionar FS Forms and Styles->SSF SAP Smart Form, ingresar nombre de smartform en Object Name, y seleccionar Source & Target language.

Printing Several Forms in One Print Request

ejemplo programa: SF_EXAMPLE_03

ver nota SAP Note 85318 - Appending documents to existing spool

ejemplo

FORM print_and_release USING p_nodialog  "si p_dialog = space => ver pdf, sino, imprimir
                              p_data TYPE vbrk_t "tabla de vbrk
                     CHANGING p_subrc.

  DATA: lt_errortab       TYPE tsferror,
        ls_control_param  TYPE ssfctrlop,
        ls_composer_param TYPE ssfcompop,
        ls_job_info       TYPE ssfcrescl,
        l_formname        TYPE tdsfname VALUE 'ZHCMSF_MYSMARTFORM',
        l_fm_name         TYPE rs38l_fnam.

  p_subrc = 0.

  DATA(l_lines) = lines( p_data ).
  IF l_lines = 0.
    RETURN.
  ENDIF.

* determine smartform function module for invoice
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = l_formname
*     variant            = ' '
*     direct_call        = ' '
    IMPORTING
      fm_name            = l_fm_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.
  IF sy-subrc <> 0.
*   error handling
    p_subrc = sy-subrc.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    RETURN.
  ENDIF.

  ls_control_param-no_dialog = p_nodialog.
  ls_control_param-langu = sy-langu.
  ls_control_param-no_open   = 'X'.
  ls_control_param-no_close  = 'X'.

  ls_composer_param-tdimmed = 'X'.
  ls_composer_param-tddelete = 'X'.
  ls_composer_param-tdlifetime = '0'.
  ls_composer_param-tdreceiver = sy-uname.
  ls_composer_param-tdcopies = '001'.
  ls_composer_param-tdarmod = '1'.

  IF p_nodialog = 'X'.
    ls_control_param-no_dialog = space.
    ls_composer_param-tdnewid        = 'X'.
  ELSE.
    ls_composer_param-tddest = 'LOCL'.
    ls_composer_param-tdnewid        = 'X'.
    ls_control_param-getotf     = 'X'.
    ls_control_param-preview    = 'X'.
    ls_control_param-no_dialog  = 'X'.
  ENDIF.

  LOOP AT p_data INTO DATA(wa_data).
    DATA(l_tabix) = sy-tabix.
    IF l_tabix = 1.
      CALL FUNCTION 'SSF_OPEN'
        EXPORTING
          user_settings      = ' '
          control_parameters = ls_control_param
          output_options     = ls_composer_param
        EXCEPTIONS
          formatting_error   = 1
          internal_error     = 2
          send_error         = 3
          user_canceled      = 4
          OTHERS             = 5.

      IF sy-subrc <> 0.
*   error handling
        p_subrc = sy-subrc.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        RETURN.
      ENDIF.
    ENDIF.

    CALL FUNCTION l_fm_name
      EXPORTING
        control_parameters = ls_control_param
        output_options     = ls_composer_param
        user_settings      = space
        i_data             = wa_data
      IMPORTING
        job_output_info    = ls_job_info
      EXCEPTIONS
        formatting_error   = 1
        internal_error     = 2
        send_error         = 3
        user_canceled      = 4
        OTHERS             = 5.
    IF sy-subrc <> 0.
*   error handling
* Transfer SF errors to internal table
      CALL FUNCTION 'SSF_READ_ERRORS'
        IMPORTING
          errortab = lt_errortab.

      LOOP AT lt_errortab INTO DATA(wa).
        MESSAGE ID wa-msgid TYPE 'I' NUMBER wa-msgno
              WITH wa-msgv1 wa-msgv2 wa-msgv3 wa-msgv4 DISPLAY LIKE 'E'.
        EXIT.
      ENDLOOP.
      p_subrc = 4.
      RETURN.
    ENDIF.

    IF l_tabix = l_lines.
      CALL FUNCTION 'SSF_CLOSE'
        IMPORTING
          job_output_info  = ls_job_info
        EXCEPTIONS
          formatting_error = 1
          internal_error   = 2
          send_error       = 3
          OTHERS           = 4.

      IF sy-subrc <> 0.
*   error handling
        p_subrc = sy-subrc.
        MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'.
        RETURN.
      ENDIF.
    ENDIF.

    IF p_nodialog = space.
*  Preview PDF, OJO visualiza despues de Cerrar el smartform
      CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
        EXPORTING
          i_otf                    = ls_job_info-otfdata
        EXCEPTIONS ##FM_SUBRC_OK
          convert_otf_to_pdf_error = 1
          cntl_error               = 2
          OTHERS                   = 3.

    ENDIF.
  ENDLOOP.

ENDFORM.

Ejemplo usando clases

*&---------------------------------------------------------------------*
*& Report  YTEST_CLASS_SMART
*&
*&---------------------------------------------------------------------*
*& Ejemplo de Herencia:
* Padre = cl_smart , hijo = cl_smart_usuarios, notese que cl_smart_usuarios
* hereda metodos set_parameters get_otf, get_errortab, que eventualmente serán comunes para
* cualquier llamada de un smartform
*&
*&---------------------------------------------------------------------*
REPORT  ytest_class_smart.

*----------------------------------------------------------------------*
*       CLASS smart DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_smart DEFINITION ABSTRACT.
  PUBLIC SECTION.
    METHODS set_parameters IMPORTING i_form               TYPE tdsfname
                                     i_control_parameters TYPE ssfctrlop
                                     i_output_options     TYPE ssfcompop.

    METHODS get_otf EXPORTING e_otf TYPE tt_itcoo.
    METHODS get_errortab EXPORTING e_errortab TYPE tsferror.

*smartforms related
    DATA: func_module_name   TYPE rs38l_fnam,
          control_parameters TYPE ssfctrlop,
          output_options     TYPE ssfcompop,
          job_output_info    TYPE ssfcrescl,
          otf                TYPE tt_itcoo,
          errortab           TYPE tsferror.
*   data: pa_form type      tdsfname .
*  private section.
ENDCLASS.                    "smart DEFINITION

CLASS cl_smart_usuarios DEFINITION INHERITING FROM cl_smart.
  PUBLIC SECTION.
    METHODS print EXPORTING e_subrc TYPE sy-subrc.

ENDCLASS.                    "smart DEFINITION
*----------------------------------------------------------------------*
*       CLASS smart IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_smart IMPLEMENTATION.
  METHOD set_parameters.
*   pa_form  = i_form.
* determine the name of the generated function module for the SMartform
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        formname           = i_form
      IMPORTING
        fm_name            = func_module_name
      EXCEPTIONS
        no_form            = 1
        no_function_module = 2
        OTHERS             = 3.
    control_parameters = i_control_parameters.
    output_options     = i_output_options.
  ENDMETHOD.                    "set_parameters

  METHOD get_otf.
    e_otf[] = otf[].
  ENDMETHOD.

  METHOD get_errortab.
    e_errortab[] = errortab[].
  ENDMETHOD.
ENDCLASS.                    "smart IMPLEMENTATION
CLASS cl_smart_usuarios IMPLEMENTATION.
  METHOD print.
* call the generated function module of the form
    CALL FUNCTION func_module_name
      EXPORTING
        control_parameters = control_parameters
        output_options     = output_options
*       user_settings      = space
      IMPORTING
        job_output_info    = job_output_info
      EXCEPTIONS
        formatting_error   = 1
        internal_error     = 2
        send_error         = 3
        user_canceled      = 4
        my_exception       = 5
        OTHERS             = 6.
    e_subrc = sy-subrc.
    IF sy-subrc <> 0.
* Implement suitable error handling here
*     Transfer SF errors to internal table

      CALL FUNCTION 'SSF_READ_ERRORS'
        IMPORTING
          errortab = errortab.
    ENDIF.
    otf[]  = job_output_info-otfdata[].
  ENDMETHOD.                    "print
ENDCLASS.                    "smart_usuarios IMPLEMENTATION
******************************
DATA my_smart TYPE REF TO cl_smart_usuarios.

START-OF-SELECTION.

  CREATE OBJECT my_smart.

START-OF-SELECTION.

  PERFORM print_data USING 'X'.

*&---------------------------------------------------------------------*
*&      Form  print_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM print_data USING p_otf.
*smartforms related
  DATA: ls_control_parameters TYPE ssfctrlop,
        ls_output_options     TYPE ssfcompop.
  DATA: l_form LIKE ssfscreen-fname .

  l_form = 'ZSF_TEST'. "crear smartform dummy con texto HOLA MUNDO
*  ls_output_options-tdnewid = 'X'.
*  ls_output_options-tdimmed = 'X'.
*  ls_output_options-tddelete = 'X'.
*  ls_control_parameters-no_dialog = ' '.

  IF p_otf <> 'X'.
    ls_control_parameters-no_dialog = space.
    ls_output_options-tdnewid       = 'X'.
  ELSE.
    ls_control_parameters-device = 'PRINTER'.
    ls_output_options-tdnewid        = 'X'.
    ls_control_parameters-getotf     = 'X'.
    ls_control_parameters-preview    = ' '.
    ls_control_parameters-no_dialog  = 'X'.
  ENDIF.

  my_smart->set_parameters( EXPORTING i_form = l_form
                                      i_control_parameters = ls_control_parameters
                                      i_output_options = ls_output_options
                                      ).
  my_smart->print( IMPORTING e_subrc = DATA(l_subrc)
                  ).

  IF l_subrc <> 0.
    my_smart->get_errortab( IMPORTING e_errortab = DATA(lt_errortab) ).
    LOOP AT lt_errortab INTO DATA(wa).
      MESSAGE ID wa-msgid TYPE 'I' NUMBER wa-msgno
            WITH wa-msgv1 wa-msgv2 wa-msgv3 wa-msgv4 DISPLAY LIKE 'E'.
      EXIT.
    ENDLOOP.
    RETURN.
  ENDIF.

  IF p_otf = 'X'.
    my_smart->get_otf( IMPORTING e_otf = DATA(lt_otf) ).

*  Preview PDF.
    CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
      EXPORTING
        i_otf                    = lt_otf[]
      EXCEPTIONS ##fm_subrc_ok
        convert_otf_to_pdf_error = 1
        cntl_error               = 2
        OTHERS                   = 3.
  ENDIF.
  lt_otf = my_smart->otf.  "otf es accesible pues es PUBLIC si fuese PRIVATE hay que usar get_otf
ENDFORM.

Código de Barra

Ver nota 645158

EJEMPLO código de barras 2 dimensiones PDF 417

  1. Crear font en SE73; Cod.Barras Sistema; Modificar.
  2. Crear Font, en pregunta "Nva.tecnología cod.barras..." seleccionar nv.(nuevo).
  3. Dar nombre y descripción.
  4. Seleccionar PDF417.

Configurar font

SAP Bar Code Name    ZPDF417
Bar Code Symbology   PDF 417                       
Bar Code Alignment   Normal                        
Narrow Module Width  05                            
Linear Height        00150                         
Single Row Height    00010                         
# of Columns (1-30)  00                            
# of Rows (3-90)     00                            
SecurityLevel        3                             
Truncation

Crear estilo(SMARTFORMS) y crear formato carácter CB, y en Parametriz.Estandard, Código de barras, especificar ZPDF417.

En Smartform, colocar string de código de barras con formato de caracter creado anteriormente.

*	 	<CB><&TIMBRE+1(250)&&TIMBRE+251(250)&&TIMBRE+501(250)&
=	 	&TIMBRE+751(250)&&TIMBRE+1001(250)&&TIMBRE+1251(250)&</>