Convert internal table into pdf

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
Alexius
Posts: 66
Joined: Wed Dec 10, 2008 9:30 pm

Convert internal table into pdf

Post by Alexius » Thu Mar 19, 2009 5:37 am

Hi All,

I have a requirement to save an internal table to .pdf file. The internal table is populated from user exit in query (TCode SQ01).
I already tried to create a spool number, write the internal table records, then convert the spool number to pdf table using CONVERT_ABAPSPOOLJOB_2_PDF function module. The function module ran successfully, but it didn't work. When I download the .pdf table, it was corrupt and couldn't be opened.

I looked at SP02 and my spool type was RAW document. Was this which cause the function module fail to convert the spool no?

Has anyone have similar experience? Please do enlighten me.

Thanks,

Regards,

Alexius

Below is the code fragment

Code: Select all

      
     DATA :  v_handle        TYPE sytabix,
                 v_spoolid       TYPE rspoid,
                 v_rc            TYPE c,
                 v_errmsg        TYPE c,
                 v_pdf_bytecount TYPE i,
                 it_pdf          TYPE tlinetab.

      DATA  : wa_outtab       TYPE text4096.

      CALL FUNCTION 'RSPO_OPEN_SPOOLREQUEST'
        EXPORTING
          dest       = 'LOCL'
        IMPORTING
          handle     = v_handle
          spoolid    = v_spoolid
          rc         = v_rc
          errmessage = v_errmsg.

      LOOP AT outtab ASSIGNING <fs_outtab>.
        WRITE <fs_outtab> TO wa_outtab .
        CALL FUNCTION 'RSPO_WRITE_SPOOLREQUEST'
          EXPORTING
            handle           = v_handle
            text             = wa_outtab  "<fs_outtab>
          IMPORTING
            rc               = v_rc
            errmessage       = v_errmsg
          EXCEPTIONS
            handle_not_valid = 1
            OTHERS           = 2.
        IF sy-subrc <> 0.
*         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDLOOP.

      CALL FUNCTION 'RSPO_CLOSE_SPOOLREQUEST'
        EXPORTING
          handle           = v_handle
        IMPORTING
          rc               = v_rc
          errmessage       = v_errmsg
        EXCEPTIONS
          handle_not_valid = 1
          OTHERS           = 2.

      " convert spool number to PDF
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
        EXPORTING
          src_spoolid   = v_spoolid
          no_dialog     = ' '
        IMPORTING
          pdf_bytecount = v_pdf_bytecount
        TABLES
          pdf           = it_pdf.

      CALL METHOD cl_gui_frontend_services=>file_save_dialog
        EXPORTING
          default_file_name = '.pdf'
          file_filter       = '.pdf'
        CHANGING
          filename          = l_filename
          path              = l_path
          fullpath          = l_fullpath
          user_action       = l_user_action.

      IF l_user_action <> '9'.
        CALL FUNCTION 'GUI_DOWNLOAD'
          EXPORTING
            bin_filesize = v_pdf_bytecount
            filename     = l_fullpath
            filetype     = 'BIN'
          TABLES
            data_tab     = it_pdf.
      ENDIF.
Regards,

Alexius

BradB
Posts: 685
Joined: Wed Mar 22, 2006 10:27 am
Location: Standing right behind you

Re: Convert internal table into pdf

Post by BradB » Thu Mar 19, 2009 7:05 am

That's not exactly the way I would have written it, but why would you want to write an internal table to spool and save it as a PDF file??? What use is that? Why wouldn't you write the table from the query result to a CSV, TXT, etc. file?
Ironman Triathlete and SAP Dev/Config Expert
(which is harder?)

Alexius
Posts: 66
Joined: Wed Dec 10, 2008 9:30 pm

Re: Convert internal table into pdf

Post by Alexius » Thu Mar 19, 2009 9:41 pm

BradB wrote:That's not exactly the way I would have written it, but why would you want to write an internal table to spool and save it as a PDF file??? What use is that? Why wouldn't you write the table from the query result to a CSV, TXT, etc. file?
Because it's the enhancement requirement. There are options to save the internal table into CSV, TXT, or PDF file. For CSV n TXT I didn't find any difficulties since they're quite straightforward, but for PDF I don't know how to directly download an internal table into pdf file, so I write the internal table to spool first, then convert the spool number into PDF.
Regards,

Alexius

sunchecs
Posts: 111
Joined: Mon Sep 29, 2003 10:07 pm
Contact:

Re: Convert internal table into pdf

Post by sunchecs » Fri Mar 20, 2009 3:59 am

May be you can try to convert the internal table to OTF and then convert to PDF.
I'm also attach a sample code for you looking forwards.

Code: Select all

data: filesize type i.
data header like thead.
data options like itcpo.
data result like itcpp.

data otf like itcoo occurs 1000 with header line.
data lines like tline occurs 100 with header line.

parameters p_file like rlgrap-filename.

lines-tdline = 'Hello....For testing only....'.
append lines.

*call function 'GET_TEXT_PRINT_PARAMETERS'
*     exporting
*          options          = options
*          format_itf       = ' '
*          no_print_buttons = ' '
*     importing
*          newoptions       = options
**         PRINT_FORMAT     =
*     exceptions
*          canceled         = 1.
*
*check sy-subrc = 0.
options-TDDEST = 'SB01'.
options-TDNEWID = 'X'.
options-tdgetotf = 'X'.
call function 'PRINT_TEXT'
     exporting
          device        = 'PRINTER'
          dialog        = ' '
          header        = header
          options       = options
     importing
          result        = result
     tables
          lines         = lines
          otfdata       = otf
     exceptions
          canceled      = 01
          device        = 02
          form          = 03
          options       = 04
          unclosed      = 05
          unknown       = 06
          format        = 07
          textformat    = 08
          communication = 09.

* convert to PDF
call function 'CONVERT_OTF'
     exporting
          format                = 'PDF'
     importing
          bin_filesize          = filesize
     tables
          otf                   = otf
          lines                 = lines
     exceptions
          err_conv_not_possible = 1.
May be it will give you a roughly idea and you can work out on that.
Good Luck. :)

new2sapfans
Posts: 71
Joined: Thu Jan 01, 2009 11:01 am

Re: Convert internal table into pdf

Post by new2sapfans » Fri Mar 20, 2009 6:28 am

If you have a spool and just want to download it to .pdf,
then submit to program RSTXPDFT4 with spoolid and path for the PDF file.

That should give you a pdf which is not corrupt (provided the spool was fine).

BradB
Posts: 685
Joined: Wed Mar 22, 2006 10:27 am
Location: Standing right behind you

Re: Convert internal table into pdf

Post by BradB » Fri Mar 20, 2009 7:00 am

Alexius wrote:
BradB wrote:That's not exactly the way I would have written it, but why would you want to write an internal table to spool and save it as a PDF file??? What use is that? Why wouldn't you write the table from the query result to a CSV, TXT, etc. file?
Because it's the enhancement requirement. There are options to save the internal table into CSV, TXT, or PDF file. For CSV n TXT I didn't find any difficulties since they're quite straightforward, but for PDF I don't know how to directly download an internal table into pdf file, so I write the internal table to spool first, then convert the spool number into PDF.
It's not an enhancement 'requirement', it's an option, but I was just curious why you would need it. I see absolutely no value in having an internal table in a PDF doc...
Ironman Triathlete and SAP Dev/Config Expert
(which is harder?)

sapfansmark
Posts: 1
Joined: Thu Jan 29, 2009 10:50 pm

Re: Convert internal table into pdf

Post by sapfansmark » Tue Mar 31, 2009 11:33 pm

Hi Alexius

Did you manage to resolve this I am trying something similar and am getting the same result

Thanks

Mark

Alexius
Posts: 66
Joined: Wed Dec 10, 2008 9:30 pm

Re: Convert internal table into pdf

Post by Alexius » Sun Apr 05, 2009 9:13 pm

sapfansmark wrote:Hi Alexius

Did you manage to resolve this I am trying something similar and am getting the same result

Thanks

Mark
Hi Mark,

It turned out that the internal table should be outputted first, then the report output is sent to spool, then the spool is converted to pdf.
There's a possibility that not all columns can be displayed (ie: large number of columns), but it's acceptable by the user.


Alexius
Regards,

Alexius

bucka
Posts: 291
Joined: Sat Jun 18, 2005 2:09 am
Location: Ballarat, Victoria, Australia

Re: Convert internal table into pdf

Post by bucka » Sun Apr 12, 2009 1:48 am

I'd love to see the Functional Specification for this requirement.
Especially the reasoning for a pdf output.
Kind Regards,

Ron Johns.

The older I get the better I was.

nabritta
Posts: 1
Joined: Sat Nov 14, 2009 10:53 pm

Re: Convert internal table into pdf

Post by nabritta » Wed Nov 18, 2009 2:19 am

How do you get the hyperlinks in a pdf to work if your sending the pdf to someone? Ive created a pdf with hyperlinks in that for example you click the order now, a word document opens up with the order form in it. However i send the pdf to a friend to see if it works but the buttons dont work anymore. How do i get it to all work?
market samurai ~ marketsamurai ~ marketsamurai.com

VLozano
Posts: 5142
Joined: Mon Sep 13, 2004 8:17 am
Location: Idiocity
Contact:

Re: Convert internal table into pdf

Post by VLozano » Wed Nov 18, 2009 2:33 am

And you had to raise from dead an old thread. Nice move.

Let's try something: you create a new thread for your problem, adding more information about your created pdf, and we try to give you some hints if we can. Anyways, I doubt it would be an ABAP problem, but a lack of knowledge about pdf internals.
Tuly Idiots
Because we know we are part of the problem

Post Reply