Categorias

Gerar relatório em PDF com ABAP

Programa tem a funcionalidade de visualizar através do Adobe Reader (PDF) um relatório desenvolvido em SmartForms.

************************************************************************
* Programa : Gera um arquivo PDF a partir de um relatório desenvolvido
*            em Smartforms
* Autor    : Antonio Mosca Júnior
* Data     : 07/08/2007
************************************************************************

REPORT yo_emite_pdf.

****************************************************************
* Definições
****************************************************************
DATA:  fm_name              TYPE rs38l_fnam,
       job_output_info      TYPE ssfcrescl,
       document_output_info TYPE ssfcrespd,
       job_output_options   TYPE ssfcresop,
       output_options       TYPE ssfcompop,
       control_parameters   TYPE ssfctrlop,
       lt_otfdata           TYPE TABLE OF itcoo.



****************************************************************
* Inicialização
****************************************************************
INITIALIZATION.

  SELECTION-SCREEN BEGIN OF BLOCK bl01.
  SELECTION-SCREEN SKIP.

  PARAMETERS:     p_form(30)  TYPE c  OBLIGATORY.

  SELECTION-SCREEN SKIP.
  SELECTION-SCREEN END OF BLOCK bl01.



****************************************************************
* Principal
****************************************************************
START-OF-SELECTION.

  control_parameters-device    = 'PRINTER'.
  control_parameters-no_dialog = 'X'.
  control_parameters-preview   = 'X'.
  control_parameters-getotf    = 'X'.
  output_options-tdnoprint     = 'X'.



* *** chamado do formulario Smartforms
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
       EXPORTING
            formname           = p_form
       IMPORTING
            fm_name            = fm_name
       EXCEPTIONS
            no_form            = 1
            no_function_module = 2
            OTHERS             = 3.

  CALL FUNCTION fm_name
       EXPORTING
            output_options     = output_options
            control_parameters = control_parameters
            user_settings      = 'X'
       IMPORTING
            job_output_info    = job_output_info
       EXCEPTIONS
            formating_error    = 1
            internal_error     = 2
            send_error         = 3
            user_canceled      = 4
            OTHERS             = 5.


* *** chamado do relatório em PDF
  lt_otfdata[] = job_output_info-otfdata[].

  CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
       EXPORTING
            i_otf                    = lt_otfdata
       EXCEPTIONS
            convert_otf_to_pdf_error = 1
            cntl_error               = 2
            OTHERS                   = 3.
  .
  DATA: l_dummy  TYPE STANDARD TABLE OF tline,
        pdf_data TYPE xstring,
        pdf_size TYPE i.

  CLEAR: pdf_data, pdf_size.

* convert otf to pdf
  CALL FUNCTION 'CONVERT_OTF'
       EXPORTING
            format                = 'PDF'
       IMPORTING
            bin_filesize          = pdf_size
            bin_file              = pdf_data
       TABLES
            otf                   = lt_otfdata[]
            lines                 = l_dummy
       EXCEPTIONS
            err_max_linewidth     = 1
            err_format            = 2
            err_conv_not_possible = 3
            OTHERS                = 4.

**** @ all rigths reserved ********************
**** Produced by MOSCA ************************