cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Converting Spool to PDF Document

Former Member
0 Likes
3,106

Hi Gurus,

      Can anyone tell me how to convert the Spool to a PDF Document ??

Thanks & Regards,

Sameej T.K.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Likes

Hi, ABAP experts,

Do you know where the PDF file is stored after the function module "CONVERT_ABAPSPOOLJOB_2_PDF" is executed? is it possible to store the converted PDF file in the frontend computer and how? thanks in advance,

J. Zhan

thomas_jung
Developer Advocate
Developer Advocate
0 Likes

Wll the PDF contents are passed back to the calling program in an internal table of structure TLINE.  You then can covert it to a table format that is ready to attach in an Email or write to the frontend or the server. The following is the routine that I usually use to do this:

data: ipdf        like tline occurs 0 with header line.

data: objbin           like solisti1 occurs 10 with header line.

perform convert_pdf tables ipdf

                             objbin.

*&----


*

*&      Form convert_pdf

*&----


*

*       Take the PDF information returned by the function module

*       and convert it to a file readable format. It currently is

*       in a printable-only format.

*----


*

*      -->P_IPDF PDF Source

*      -->P_OBJBIN PDF Destination

*----


*

form convert_pdf tables   t_source_tab structure ipdf

                          t_target_tab structure objbin.

  data: l_hfeld(1600) type c,

         l_offset type p,

         l_tabix like sy-tabix,

         l_max type i,

         l_linecount_source type i,

         l_length_source type i,

         l_length_target type i.

  • Zeilenlänge des Quell-PDF-Files

  describe field t_source_tab length l_length_source.

  • Zeilenlänge der Ziel-Mime-Tabelle

  describe field t_target_tab length l_length_target.

  • Zeilenanzahl des Quell-PDF-Files

  describe table t_source_tab lines l_linecount_source.

  • Die maximale Zielgröße wird durch das Feld l_hfeld begrenzt.

  l_max = l_length_target + l_length_source.

*  IF L_MAX > 1600.

*

*    RAISE CONVERT_NOT_POSSIBLE.

*

*  ENDIF.

  refresh t_target_tab.

  loop at t_source_tab.

    l_tabix = sy-tabix.

    move t_source_tab to l_hfeld+l_offset.

  • falls letzte zeile der quelltabelle erreicht

    if l_tabix = l_linecount_source.

      l_length_source = strlen( t_source_tab ).

    endif.

    l_offset = l_offset + l_length_source.

    while l_offset ge l_length_target.

      clear t_target_tab.

      t_target_tab = l_hfeld(l_length_target).

      append t_target_tab.

      shift l_hfeld by l_length_target places.

      l_offset = l_offset - l_length_target.

    endwhile. " l_offset ge p_length_target

  • falls letzte zeile der quelltabelle erreicht

    if l_tabix = l_linecount_source.

      if l_offset gt 0.

        clear t_target_tab.

        t_target_tab = l_hfeld(l_offset).

        append t_target_tab.

      endif. " l_offset gt 0

    endif. " l_tabix = l_linecount_lines

  endloop. " p_source_tab

endform.                    " convert_pdf

These results can be written to the frontend using a call to GUI_DOWNLOAD or CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD.

Former Member
0 Likes

As an alternative, SAP do provide a device type to issue print output in PDF format.  

Upload this device type as detailed in SAPnet note 317851 and print your output to a printer defined with this device type.  It is then possible to copy away your spool file to any desired location by changing the parameter rspo/host_spool/print for your printer to a script of your own design.

Former Member
0 Likes

hey, just try the reports

RSTXPDFT4 "Konvertiere SAPscript (OTF) oder ABAP-Listen-Spooljob nach PDF "

or RSTXPDFT5 "Test: GUI-Download eines Spoolauftrags"

and you will be able to download the pdf to your frontend.

Former Member
0 Likes

Thank you all...

Former Member
0 Likes

Hi Wei-Ming Tchay ,

I am working in SAP GUI FOR HTML for upgration from 5.00 to ECC 6.0.

In the ECC 5.0 One of my Tranaction is having reports. all the reports we are converting into PDF.

It is working fine in ECC 5.0.

In ECC 6.0 because of UNICODE i am getting error "File does not begin with '%PDF-'.

i serached the OSS notes I found 1320163 .

In my program I am using FM to get PDF in Bytes CONVERT_ABAPSPOOLJOB_2_PDF.

The out put is coming in Internal Table.

I am using macros.

MIME-DOWNLOAD T_PDF MIMELENGTH 'application/pdf'. getting the PDF in ECC5.0 .

but in ECC 6.0 Unicode it is error.

I thought as per the note 1320163 i can convert into Xstring after that I can move to Table.

Kindly help me If you done for the MIME-DOWNLOAD Macros.

Thanks in advance.

dev

Former Member
0 Likes

Hi, ABAP experts,

Do you know where the PDF file is stored after the function module "CONVERT_ABAPSPOOLJOB_2_PDF" is executed? is it possible to store the converted PDF file in the frontend computer and how? thanks in advance,

J. Zhan

thomas_jung
Developer Advocate
Developer Advocate
0 Likes

This is from a previous posting...

If you want to go to PDF, there is another approach.  There are SAP functions to convert SPOOL to PDF. They are CONVERT_ABAPSPOOLJOB_2_PDF and CONVERT_OTFSPOOLJOB_2_PDF. What you can do here is schedule your report as one step in a job and then your post processing as another step. You can use GET_JOB_RUNTIME_INFO to get the jobcount and jobname of the currently running job. You can then read back in table TBTCP to get the spool list number (listident) of a previous step.

Example:

clear jselect.

jselect-jobname = ''.

  jselect-username = '*'.

****Have this program get its own Job Name

  call function 'GET_JOB_RUNTIME_INFO'

       importing

*         EVENTID =

*         EVENTPARM =

*         EXTERNAL_PROGRAM_ACTIVE =

          jobcount = jselect-jobcount

          jobname = jselect-jobname

*         STEPCOUNT =

       exceptions

            no_runtime_info = 1

            others = 2.

****Read the spool number for this job step.

  clear tbtcp.

  select single listident from tbtcp

         into tbtcp-listident

         where jobname = jselect-jobname

           and jobcount = jselect-jobcount

           and stepcount = step.

  if tbtcp-listident = 0.

    message i009 with step.

  endif.

data: spool_id like tsp01-rqident.

  move tbtcp-listident to spool_id.

****Is this ABAP List Processing?

  if abap = 'X'.

    call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

      exporting

        src_spoolid = spool_id

*       NO_DIALOG =

*       DST_DEVICE =

*       PDF_DESTINATION =

*     IMPORTING

*       PDF_BYTECOUNT =

*       PDF_SPOOLID =

*       LIST_PAGECOUNT =

*       BTC_JOBNAME =

*       BTC_JOBCOUNT =

      tables

        pdf = ipdf

     exceptions

       err_no_abap_spooljob = 1

       err_no_spooljob = 2

       err_no_permission = 3

       err_conv_not_possible = 4

       err_bad_destdevice = 5

       user_cancelled = 6

       err_spoolerror = 7

       err_temseerror = 8

       err_btcjob_open_failed = 9

       err_btcjob_submit_failed = 10

       err_btcjob_close_failed = 11

       others = 12.

    if sy-subrc <> 0.

      message i016 with sy-subrc.

    endif.

  else.

****Or is this SAPscript?

    call function 'CONVERT_OTFSPOOLJOB_2_PDF'

      exporting

        src_spoolid = spool_id

*       NO_DIALOG =

*       DST_DEVICE =

*       PDF_DESTINATION =

*     IMPORTING

*       PDF_BYTECOUNT =

*       PDF_SPOOLID =

*       OTF_PAGECOUNT =

*       BTC_JOBNAME =

*       BTC_JOBCOUNT =

      tables

        pdf = ipdf

     exceptions

       err_no_otf_spooljob = 1

       err_no_spooljob = 2

       err_no_permission = 3

       err_conv_not_possible = 4

       err_bad_dstdevice = 5

       user_cancelled = 6

       err_spoolerror = 7

       err_temseerror = 8

       err_btcjob_open_failed = 9

       err_btcjob_submit_failed = 10

       err_btcjob_close_failed = 11

       others = 12.

    if sy-subrc <> 0.

      message i016 with sy-subrc.

    endif.

  endif.