Difference between revisions of "SAP ABAP SMARTFORMS"

From SapWiki
(Created page with "== ejemplo de función que retorna smartform en BASE 64 FUNCTION zhr_authpermisos_pdf. *"---------------------------------------------------------------------- *"*"Interfas...")
 
Line 1: Line 1:
== ejemplo de función que retorna smartform en BASE 64
+
== ejemplo de función que retorna smartform en BASE 64==
 
  FUNCTION zhr_authpermisos_pdf.
 
  FUNCTION zhr_authpermisos_pdf.
 
  *"----------------------------------------------------------------------
 
  *"----------------------------------------------------------------------

Revision as of 18:19, 26 March 2020

ejemplo de función que retorna smartform en BASE 64

FUNCTION zhr_authpermisos_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: w_formname          TYPE tdsfname VALUE 'ZSF_MY_SMARTFORM',
        lf_fm_name          TYPE rs38l_fnam,
        ls_control_param    TYPE ssfctrlop,
        ls_composer_param   TYPE ssfcompop,
        ga_job_output_info  TYPE ssfcrescl.
        
*insert some logic here
  
*
*--------------------------------------------------------------------*
* call Smartform
*--------------------------------------------------------------------*
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = w_formname
    IMPORTING
      fm_name            = lf_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 lf_fm_name
    EXPORTING
      control_parameters = ls_control_param
      output_options     = ls_composer_param
      i_data             = wa_data
    IMPORTING
      job_output_info    = ga_job_output_info
*              TABLES
*     detalle            = it_ccnom1
    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.

  ltd_otf[]  = ga_job_output_info-otfdata[].
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
*     max_linewidth         = 800
    IMPORTING
      bin_filesize          = lv_bytes
      bin_file              = bin_file
    TABLES
      otf                   = ltd_otf
      lines                 = gt_pdfdata
    EXCEPTIONS ##FM_SUBRC_OK
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      OTHERS                = 4.

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

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


ENDFUNCTION.