cancel
Showing results for 
Search instead for 
Did you mean: 

Display Smartform Pdf output in ABAP Webdynpro application

Udo_Ahle
Explorer
0 Kudos
488

Hello,

there is a solution for displaying Smartform output in Java Webdynpro application in this forum. Since i want to start an project in ABAP Webdynpro i need a solution for this technology since i don't want to recreate all the paperwork again using Adobe. Is there any solution available?

Thanks

Udo Ahle

View Entire Topic
Udo_Ahle
Explorer
0 Kudos

Hello,

this is the solution which i was able to implement using the hints given by Heidi and Thomas. Thank you for the support. With this solution it is possible to reuse oldstyle sapscripts and smartforms in todays environment. Here is the sample code which solves the problem:

In WDA you define for example a pushbutton to start the display of the PDF.

In the onaction method you implement:

method ONACTIONSHOW_PDF .
  data LX_pdf type xstring.

* get PDF from existing sapscript or smatform
  call function 'Y_PDF_GET' destination '46c'
    IMPORTING
      ex_PDF = LX_PDF.

* append the pdf to the response
  cl_wd_runtime_services=>attach_file_to_response(
    i_filename  = 'Hello.PDF'
    i_content   = lx_pdf
    i_mime_type = 'application/pdf'
    i_in_new_window = 'X'
    i_inplace       = 'X' ).

endmethod.

The function 'Y_PDF_GET' is implemented as follows:

FUNCTION Y_PDF_GET .
*"--------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     VALUE(EX_PDF) TYPE  XSTRING
*"  TABLES
*"      ET_OTF STRUCTURE  ITCOO OPTIONAL
*"--------------------------------------------------------
  data: lf_filesize type i,
        lt_otf type table of ITCOO,
        lt_lines type table of tline,
        tline type tline.
* start sapscript or smatforms and return
  perform make_otf.

  CALL FUNCTION 'READ_OTF_FROM_MEMORY'
    TABLES
      OTF                = lt_otf
   EXCEPTIONS
     MEMORY_EMPTY       = 1
     OTHERS             = 2
            .

  et_otf[] = lt_otf.

  CALL FUNCTION 'CONVERT_OTF'
   EXPORTING
     FORMAT                      = 'PDF'
*   MAX_LINEWIDTH               = 132
*   ARCHIVE_INDEX               = ' '
   IMPORTING
     BIN_FILESIZE                = lf_filesize
    TABLES
      OTF                         = lt_otf
      LINES                       = lt_lines
   EXCEPTIONS
     ERR_MAX_LINEWIDTH           = 1
     ERR_FORMAT                  = 2
     ERR_CONV_NOT_POSSIBLE       = 3
     OTHERS                      = 4
            .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* convert tline to xstring as needed in 
* in web dynpro             
  field-symbols <X>.
  data: st(268) type c.
  data l1 type i.
  data len type i.
  data maxline type i value 134.
  l1 = 0.
  loop AT lt_lines INTO tline.
    clear st.
    st+l1(maxline) = tline.
    len = maxline + l1.
    l1 = maxline - strlen( tline ).
    ASSIGN st TO <x> TYPE 'X'.
    CONCATENATE ex_pdf <x>(len) INTO ex_pdf.
  endloop.
ENDFUNCTION.

The make_otf for sapscript is the following:

* the next attribute enables the otf output.
* no other output will be generated
<b>options-TDGETOTF = 'X'</b>
  CALL FUNCTION 'OPEN_FORM'
       EXPORTING
*         APPLICATION        = 'TX'
*         ARCHIVE_INDEX      = ARCHIVE_INDEX
         ARCHIVE_PARAMS     = ARCHIVE_PARAMS
            DEVICE             = DEVICE
            DIALOG             = ' '
            FORM               = FORM
            LANGUAGE           = language
           OPTIONS            = OPTIONS
*     IMPORTING
*          LANGUAGE           =
*          NEW_ARCHIVE_PARAMS =
*          RESULT             =
       EXCEPTIONS
            CANCELED           = 1
            DEVICE             = 2
            FORM               = 3
            OPTIONS            = 4
            UNCLOSED           = 5
            OTHERS             = 6.

*... make some write forms
  data lT_OTF	type table of	ITCOO.

* get the otf data
  CALL FUNCTION 'CLOSE_FORM'
*     IMPORTING
*          RESULT   = result
       TABLES
           OTFDATA  = lt_otf
       EXCEPTIONS
            UNOPENED = 1
            OTHERS   = 2.

* put otf into memory for later usage
  if not lt_otf is initial.
    CALL FUNCTION 'SAVE_OTF_TO_MEMORY'
* EXPORTING
*   MEMORY_KEY       = 'DEF_OTF_MEMORY_KEY'
      TABLES
        OTF              = lt_otf.
  endif.

For Smartforms technology it is possible to implement the same concept.