abap smartforms 转换成pdf xtring

最近客户有一个需求是需要讲发票的smartform 发送到第三方系统。

原先的做法是,SAP只是发送发票数据过去,由第三方系统去自己创建PDF打印。

那么就遇到了一个问题,SAP中的发票打印产生修改的时候。第三方系统也要同步修改,

涉及到数据发送不完全的,还需要修改发送数据的接口。

这样每次的变更,对各系统来说就比较麻烦且工作量大,效率也不高。

后来研究了下,发现可以将smartform转换成PDF,再转成xstring去发送,

对方收到之后,再转回PDF。

  DATA: lv_func_name          TYPE rs38l_fnam. "数据元素
  DATA: lw_output_options     TYPE ssfcompop .
  DATA: ls_document_output    TYPE ssfcrespd,
        ls_job_output         TYPE ssfcrescl,
        ls_job_options        TYPE ssfcresop,
        ls_control_parameters TYPE ssfctrlop. "Smart Forms: 控制结构.
  DATA: lv_message            TYPE string.
  DATA: lv_bin_size    TYPE i,
        lv_pdf_xstring TYPE xstring.
  DATA: lt_tline              TYPE STANDARD TABLE OF tline.

 CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = 'ZSD_SF_INVOICE_NEW'
    IMPORTING
      fm_name            = lv_func_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.
  ENDIF.
*设置不打开对话框,
  ls_control_parameters-no_dialog = 'X'.
  ls_control_parameters-langu     = sy-langu.
  ls_control_parameters-getotf    = 'X'.
  lw_output_options-tdnoprev  = 'X'.


  CALL FUNCTION lv_func_name
    EXPORTING
*     ARCHIVE_INDEX        =
*     ARCHIVE_INDEX_TAB    =
*     ARCHIVE_PARAMETERS   =
      control_parameters   = ls_control_parameters
*     MAIL_APPL_OBJ        =
*     MAIL_RECIPIENT       =
*     MAIL_SENDER          =
      output_options       = lw_output_options
*     USER_SETTINGS        = 'X'
      ls_head              = ls_head
    IMPORTING
      document_output_info = ls_document_output
      job_output_info      = ls_job_output
      job_output_options   = ls_job_options
    TABLES
      it_items             = lt_item
    EXCEPTIONS
      formatting_error     = 1
      internal_error       = 2
      send_error           = 3
      user_canceled        = 4
      OTHERS               = 5.
  IF sy-subrc <> 0.
    CALL FUNCTION 'MESSAGE_TEXT_BUILD'
      EXPORTING
        msgid               = sy-msgid
        msgnr               = sy-msgno
        msgv1               = sy-msgv1
        msgv2               = sy-msgv2
        msgv3               = sy-msgv3
        msgv4               = sy-msgv4
      IMPORTING
        message_text_output = lv_message.
  ENDIF.
*
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
    IMPORTING
      bin_filesize          = lv_bin_size
      bin_file              = lv_pdf_xstring
    TABLES
      otf                   = ls_job_output-otfdata
      lines                 = lt_tline
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf           = 4
      OTHERS                = 5.
  IF sy-subrc <> 0.
    CALL FUNCTION 'MESSAGE_TEXT_BUILD'
      EXPORTING
        msgid               = sy-msgid
        msgnr               = sy-msgno
        msgv1               = sy-msgv1
        msgv2               = sy-msgv2
        msgv3               = sy-msgv3
        msgv4               = sy-msgv4
      IMPORTING
        message_text_output = lv_message.
    RETURN.
  ENDIF.

*lv_pdf_xstring 就是我们需要的smartform xtring
*可以放到下面这个结构中
TYPES:BEGIN OF ty_invoice,
        vbeln   TYPE vbeln_vf,
        xstring TYPE xstring,
      END OF ty_invoice.
DATA: gs_invoice TYPE ty_invoice.

你可能感兴趣的:(abap)