Skip to Content
0
Former Member
Apr 08, 2009 at 11:32 AM

Read PDF Formatted Spool and write PDF File to Application Server

585 Views

Hi Experts,

After ECC 6.0, HR-W2 and W2C Form Spools are getting generated in PDF format.

We have a requirement wherein we want to read the PDF Spool Programatically and write the PDF file to Application server (Using OPEN DATASET and CLOSE DATASET)

PARAMETERS : p_spono LIKE tsp01-rqident.


DATA: pdf_data type FPCONTENT.
types: lt_pdf_table(1000) type x.
data:  l_pdf_data type standard table of lt_pdf_table,
       l_pdf_line type lt_pdf_table,
       l_offset type i,
       l_len type i,
       p_file(100) VALUE '\sapout\DVH\pdf2.pdf'.

*Read the spool content
CALL FUNCTION 'FPCOMP_CREATE_PDF_FROM_SPOOL'
    EXPORTING
    	i_spoolid = p_spono
    	i_partnum = '1'
    IMPORTING
      	e_pdf = pdf_data
*    	e_pdf_file = file
    EXCEPTIONS
    	ads_error = 1
    	usage_error = 2
    	system_error = 3
    	internal_error = 4
    OTHERS = 5.


* Modify the spool  contents to prepare internal table
  l_len = xstrlen( pdf_data ).
  while l_len >= 1000.
    l_pdf_line = pdf_data+l_offset(1000).
    append l_pdf_line to l_pdf_data.
    add 1000 to l_offset.
    subtract 1000 from l_len.
  endwhile.

  if l_len > 0.
    l_pdf_line = pdf_data+l_offset(l_len).
    append l_pdf_line to l_pdf_data.
  endif.


*--------------------------------------------------------------------
* GUI DOWNLOAD Works Fine
*--------------------------------------------------------------------
* Now pdf contents is ready , lets store in local PC
*CALL FUNCTION 'GUI_DOWNLOAD'
*  EXPORTING
*   filename                        = 'C:\Documents and Settings\Desktop\shital.pdf'
*   filetype                        = 'BIN'
*  TABLES
*    data_tab                        = l_pdf_data.

OPEN DATASET p_file FOR OUTPUT IN BINARY MODE.
IF sy-subrc <> 0.
  MESSAGE ID '00' TYPE 'E' NUMBER '398' WITH 'sy-subrc:' sy-subrc
          ' Error opening file:'(Z03) p_file.
ENDIF.

LOOP AT l_pdf_data INTO l_pdf_line.
  TRANSFER l_pdf_line TO p_file.
ENDLOOP.

CLOSE DATASET p_file.
IF sy-subrc <> 0.
  MESSAGE ID '00' TYPE 'E' NUMBER '398' WITH 'sy-subrc:' sy-subrc
          ' Error closing file:'(Z04) p_file.
ENDIF.

Currently as you can see I have commented out GUI_DOWNLOAD Function Module, But it works perfect when I try to Download file to Local Desktop.

But when I try to pass the same Contents to Application server file and then try to open it by downloading file then it opens BLANK pdf file.

As per requirements I should be able to write the file correctly on Application server and If I dowload it from there it should open PDF file correctly.

Let me know if you require further details about the issue.

Regards

Shital

Edited by: shital phadake on Apr 8, 2009 9:39 PM