For some SAP users, SAP forms are not generated with SAP internal form tools (SAP Script, Smart Forms, Adobe Forms), but the form generation is done via an external output management system (OMS). The external OMS may be Jetforms, Formscape, Streamserve or the TDS (Tentacle Document Server).

If SAP forms are generated with an external OMS, the print preview is often not possible directly in SAP. One would have to call the external OMS to see the print preview. However, a typical SAP user does not have access to the external OMS and in many cases he wants a print previwe directly in SAP before the form is printed or sent by e-mail.

Scenario

The SAP user creates the forms with an external OMS. In our example, a TDS (Tentacle Document Server) was linked to SAP ERP via an SAP PI. The raw data for this is generated in an SAP Script print program. The SAP Script form is programmed so that no form output is done, but the raw data of the form is sent to the external OMS via the SAP PI as an IDoc. Alternatively, an RDI data stream could also be generated in the SAP spool, which is then passed to the external OMS.

If the SAP user wants a print preview, an flag within the IDoc is sent to the external OMS so that it creates a PDF file and stores it as a binary object in the SAP database. The SAP application waits until the PDF file can be read and can be displayed in an HTML control within the Sapgui.

Execute the requirement

Realisierung im Druckprogramm

Vor dem Aufruf des Funktionsbausteins OPEN_FORM wird im Falle einer Druckbildansicht eine eindeutige GUID erzeugt.

* GUID bei Druckbildansicht erzeugen
  if  us_screen = abap_true.
*    CALL METHOD cl_guid_services=>create
*      IMPORTING
*        ev_guid_16 = yvbdka-guid.
    call function 'GUID_CREATE'
      importing
        ev_guid_16 = yvbdka-guid.
  endif.

Direkt vor OPEN_FORM wird die GUID in das Feld ITCPO-TDCOVTITLE geschrieben.

* Spoolparameter setzen
  if not yvbdka-guid is initial.
    lvs_itcpo-tdcovtitle = 'GUID:'.
    lvs_itcpo-tdcovtitle+5 = yvbdka-guid.
  endif.

* OPEN_FORM
  call function 'OPEN_FORM'
       exporting
            archive_index      = toa_dara
            archive_params     = arc_params
            device             = lvf_device
            dialog             = ' '
            form               = tnapr-fonam
            language           = nast-spras
            options            = lvs_itcpo
            mail_sender        = lvs_sender
            mail_recipient     = lvs_recipient
       exceptions
            canceled           = 1
            device             = 2
            form               = 3
            options            = 4
            unclosed           = 5
            mail_options       = 6
            archive_error      = 7
            others             = 8.

Das Formular wird nun erzeugt, CLOSE_FORM wird prozessiert und das SAP Script-Formular geht als Idoc an das externe OMS.

Wenn die GUID gefüllt ist, dann druckt das externe OMS nicht das Formular, sondern reicht das PDF im Format BASE64 an die SAP PI weiter.

Die SAP PI ruft nun einen Proxy im ERP auf und übergibt die PDF-Datei in folgender Struktur.

SAP-Forms-Externes-OMS-Struktur-Proxy1

The RAWSTRING content field contains the PDF file.

sap-forms-externes-oms-struktur-proxy2

In a specially developed function module Z_PI_SAVE_PDF_FROM_TDS, the PDF file is saved with correspondence to the GUID in table ZTDS_PREVIEW. The function module Z_PI_SAVE_PDF_FROM_TDS is included in the method of the proxy in SAP ERP.

SAP Forms Externes OMS-Struktur Tabelle PDF Daten

This is how the PDF file in the format BASE64 looks in the database (transaction SE16).

SAP Forms Externes OMS-Tabelleninhalt PDF Daten

Coding im Funktionsbaustein Z_PI_SAVE_PDF_FROM_TDS:

FUNCTION z_pi_save_pdf_from_tds.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(IT_CONTENT) TYPE  ZPI_CONTENT_T OPTIONAL
*"----------------------------------------------------------------------

* Deklarationen ------------------------------------------------------ *
  DATA: ls_content        TYPE zpi_content_s,
        ls_preview        type ztds_preview.
* Uhrzeit holen ------------------------------------------------------ *
  GET TIME.

* PDF aus TDS sichern ------------------------------------------------ *
  LOOP AT it_content INTO ls_content.
    MOVE-CORRESPONDING ls_content TO ls_preview.
    ls_preview-ernam = sy-uname.
    ls_preview-erdat = sy-datum.
    ls_preview-eruhr = sy-uzeit.
    MODIFY ztds_preview from ls_preview.
  ENDLOOP.

* ... und sofort verbuchen ------------------------------------------- *
  COMMIT WORK.

ENDFUNCTION.

The PDF is now in the table and can now be displayed on the screen.

In the function module CLOSE_FORM an enhancement was implemented directly at the end, where the PDF is then displayed in an HTML control on the screen.

SAP Forms Externes OMS-Enhancement bei CLOSE_FORM

Coding in Enhancement at the end of function module CLOSE_FORM:

ENHANCEMENT 1  ZZ_TDS_PREVIEW.    "active version

* Im folgenden wird bei einer Druckbildansicht aus dem TDS ein Dynpro    * mit einem HTML-Control angezeigt, der das Formular als PDF zeigt.
  data: lv_guid        type guid_16.
  if result-tdcovtitle+0(5) = 'GUID:'.
    lv_guid = result-tdcovtitle+5.
    CALL FUNCTION 'Z_FRM_PRINT_PREVIEW_FROM_TDS'
      EXPORTING
        iv_guid = lv_guid.
  endif.

ENDENHANCEMENT.

The function module Z_FRM_PRINT_PREVIEW_FROM_TDS now polls a total of 10 x with a delay of 1 sec to the GUID on the table ZTDS_PREVIEW and shows the PDF in an HTML control. If nothing is found, it is aborted after 10 seconds.

Coding in function module Z_FRM_PRINT_PREVIEW_FROM_TDS:

FUNCTION-POOL zfrm_preview_01 MESSAGE-ID zfrm.

* TYPES -------------------------------------------------------------- *
TYPES: tt_pdf           TYPE TABLE OF sdokcntbin.

* OBJEKTREFERENZEN --------------------------------------------------- *
DATA: go_viewer         TYPE REF TO i_oi_document_viewer,
      go_container      TYPE REF TO cl_gui_custom_container.

* INTERNE TABELLEN --------------------------------------------------- *
DATA: gt_pdf            TYPE tt_pdf.

* HILFSFELDER -------------------------------------------------------- *
DATA: subrc             TYPE sysubrc,
      gv_file_size      TYPE i,
      gv_guid           TYPE guid_16,
      gv_counter        TYPE i.
DATA: go_timer          TYPE REF TO cl_gui_timer.

*----------------------------------------------------------------------*
*       CLASS lcl_receiver DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_receiver DEFINITION.

  PUBLIC SECTION.
    METHODS:
      handle_finished FOR EVENT finished OF cl_gui_timer.


ENDCLASS.                    "lcl_receiver DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_receiver IMPLEMENTATION.

  METHOD handle_finished.

    DATA: lv_count_c(5)  TYPE c.

    ADD 1 TO gv_counter.
    WRITE gv_counter TO lv_count_c LEFT-JUSTIFIED.

    CALL METHOD go_timer->run.

    PERFORM read_pdf  USING    gv_guid
                      CHANGING subrc
                               gt_pdf
                               gv_file_size.

    IF subrc = 0.
      go_timer->cancel( ).
      CALL SCREEN 2000.
      CALL METHOD go_viewer->destroy_viewer.
      CALL METHOD go_container->free.
      FREE: go_viewer,
            go_container.
    ELSE.
      MESSAGE s001.
    ENDIF.

    IF gv_counter = 10.
      MESSAGE s002.
      LEAVE TO SCREEN 0.
    ENDIF.

  ENDMETHOD.                    "handle_finished

ENDCLASS.                    "lcl_receiver IMPLEMENTATION
 
*----------------------------------------------------------------------*
***INCLUDE LZFRM_PREVIEW_01F01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  READ_PDF
*&---------------------------------------------------------------------*
FORM read_pdf  USING    pv_guid        TYPE guid_16
               CHANGING subrc          TYPE sysubrc
                        gt_pdf         TYPE tt_pdf
                        gv_file_size   TYPE i.

* Deklarationen ------------------------------------------------------ *
  DATA: ls_preview      TYPE ztds_preview.

* Initialisieren ----------------------------------------------------- *
  CLEAR:   subrc,
           gv_file_size,
           gt_pdf,
           ls_preview.
  REFRESH: gt_pdf.

* PDF in Tabelle lesen ----------------------------------------------- *
  SELECT single * INTO ls_preview
         FROM ztds_preview
         WHERE guid = pv_guid.

  IF sy-subrc NE 0.
    subrc = 8.
    EXIT.
  ENDIF.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer          = ls_preview-content
      append_to_table = 'X'
    IMPORTING
      output_length   = gv_file_size
    TABLES
      binary_tab      = gt_pdf.

ENDFORM.                    " READ_PDF
*&---------------------------------------------------------------------*
*&      Form  SHOW_PDF_INPLACE
*&---------------------------------------------------------------------*
FORM show_pdf_inplace .

* Deklarationen ------------------------------------------------------ *

  IF go_viewer IS INITIAL.
    CALL METHOD c_oi_container_control_creator=>get_document_viewer
      IMPORTING
        viewer = go_viewer.

    CREATE OBJECT go_container
      EXPORTING
        container_name = 'CONTAINER'.

    CALL METHOD go_viewer->init_viewer
      EXPORTING
        parent = go_container.

    CALL METHOD go_viewer->view_document_from_table
      EXPORTING
        show_inplace   = 'X'  "Mit ' ' funktioniert es einwandfrei...
        type           = 'application'
        subtype        = 'pdf'
        size           = gv_file_size
      CHANGING
        document_table = gt_pdf.
  ENDIF.

ENDFORM.                    " SHOW_PDF_INPLACE

*&---------------------------------------------------------------------*
*&      Form  SHOW_PDF_INPLACE
*&---------------------------------------------------------------------*
FORM print_preview.

  PERFORM read_pdf USING    gv_guid
                   CHANGING subrc
                            gt_pdf
                            gv_file_size.

  CHECK subrc = 0.
* Dynpro aufrufen ---------------------------------------------------- *
  CALL SCREEN 2000.

ENDFORM.                    " PRINT_PREVIEW


Dynpro 2000

PROCESS BEFORE OUTPUT.
  MODULE status_2000.
*
PROCESS AFTER INPUT.

  MODULE exit_2000 AT EXIT-COMMAND.

  MODULE user_command_2000.
sap-forms-externes-oms-enhancement-screen-painter