Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

RAWSTRING data to PDF conversion

shaik_zia
Explorer
0 Likes
6,882

Hi All,

I am using the standard FM 'SCI_INSPECT_LIST' to get the Code Inspector results. After getting the results I have to convert them as a PDF and send as an email to a user.

The output of the standard FM comes in an export parameter P_RESULTS of table type 'SCIT_REST' . In this structure there is one component called DETAIL of type RAWSTRING , now I need the data from this component to be converted into a PDF.

I tried every conversion  XSTRING TO BINARY, XSTRING to STRING, XSTRING to SOLIX, and then used GUI_DOWNLOAD to create a PDF, but with no success.

I could able to generate a PDF, but while opening the PDF I am getting an error like this - 'Adobe Acrobat Reader could not open 'file.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)'

If any one has faced similar issue, please share your inputs on how to resolve it.

Regards

Mohammed Zia

7 REPLIES 7
Read only

sridhar_meesala
Active Contributor
0 Likes
3,471

Hello,

Please try this.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

    EXPORTING

      buffer          = lv_content

      append_to_table = abap_true

    TABLES

      binary_tab      = lt_data.


  CALL METHOD cl_gui_frontend_services=>gui_download

    EXPORTING

      filename = lv_filepath

      filetype = 'BIN'

    CHANGING

      data_tab = lt_data.

Regards,

Sri.

Read only

3,471

Hi Sridhar,

Thanks for your reply.

I tried the way mentioned by you. I am able to generate a PDF by this approach, but the PDF is not correct. I mean I am unable to open it. I am getting the below message when I try to open it

'Adobe Acrobat Reader could not open 'file.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)'


Regards

Mohammed Zia

Read only

Laszlo_B
Product and Topic Expert
Product and Topic Expert
0 Likes
3,471

Hello Mohammed,

what I would try in this case:

  1. get the value of SCIR_REST-DETAIL
  2. store this value in a variant or use a WRITE statement (if your application environment allows it)
  3. if there are several results, get back to point 1. with a loop, otherwise continue to point 4.
  4. after you have all required data: put them in a spool request
  5. call CONVERT_ABAPSPOOLJOB_2_PDF with the spool
  6. download the result of CONVERT_ABAPSPOOLJOB_2_PDF with CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD.

Sorry for the pseudocode...

Best regards,

Laszlo

Read only

0 Likes
3,471

Hi Mohammed,

Yes, I would try the approach mentioned by Laszlo as the table type SCIT_REST is not going to be directly compatible with the file specification necessary for PDF output.  The other option is to take the internal table and create and Adobe form output if you have ADS running and then download that for emailing to someone.

Regards,

Ryan Crosby

Read only

0 Likes
3,471

Hi Laszlo,

Thanks for your reply.

I followed the steps you have mentioned and could create a spool request, but the spool request is generated with type as "RAW DOCUMENT'' and with ZERO pages.

And when I use the FMs CONVERT_ABAPSPOOLJOB_2_PDF with CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD to convert and download PDF, I am getting a PDF with ZERO pages. When I try to open the PDF its says - There was an error opening this document. This file cannot be opened because it has no pages.

I am using the FM 'RSPO_SX_OUTPUT_TEXTDATA' to create a Spool Request. Below is the code snippet of what I am doing to create a spool request. Please see, if I am doing anything wrong.

**** RAW TO TEXT

CALL FUNCTION 'SCMS_BINARY_TO_TEXT'

   EXPORTING

     input_length          filesize

*   FIRST_LINE        = 0

*   LAST_LINE         = 0

    append_to_table    = 'X'

*   MIMETYPE         = ' '

*   WRAP_LINES     = ' '

*   ENCODING        =

  IMPORTING

    output_length         = filesize1

   TABLES

     binary_tab           = gt_tab       "In this gt_tab, I have my data from Std FM 'SCI_INSPECT_LIST'

     text_tab              = data_txt     " this table I am passing to 'RSPO_SX_OUTPUT_TEXTDATA'

  EXCEPTIONS

    failed                = 1

    OTHERS          = 2.

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

  DESCRIBE TABLE data_txt

   LINES lv_lines.

CALL FUNCTION 'RSPO_SX_OUTPUT_TEXTDATA'

  EXPORTING

*   NAME                 =

    dest                 = 'LPDF'

    rows                 = lv_lines

    startrow             = 1

    pages                = lv_lines

*   RQTITLE              =

*   RQCOPIES             =

*   RQOWNER              =

    immediately          = 'X'

  IMPORTING

    rqid                 = spoolid

   TABLES

     text_data           = data_txt

  EXCEPTIONS

    name_missing         = 1

    name_twice            = 2

    not_found               = 3

    illegal_layout          = 4

    internal_error          = 5

    size_mismatch       = 6

    OTHERS               = 7

           .

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

Read only

Laszlo_B
Product and Topic Expert
Product and Topic Expert
0 Likes
3,471

Hello Mohammed,

Stefan's answer seems to be a reliable solution - anyway, what you have mentioned seems to be happening because of the binary spool type.

I don't have the entire PDF conversion algorithm in my head, but either the whole binary spool will be skipped by the conversion program or some kind of structure information could not be found in the spool.

The "regular" way to create spool requests is:

  1. RSPO_SR_OPEN -> creates and opens a new spool request
  2. RSPO_SR_ADD_PARTS -> adds parts to the spool request
  3. RSPO_SR_CLOSE -> orders a beer for you closes the spool request.

Report RSPOPRNT is a SAP-standard program featuring these programs, you can analyse / debug it to see how this kind of spool creating works.

If you can not find RSPOPRNT in your system, see SAP Note #1318419 - Programm RSPOPRNT missing after upgrade.

Otherwise, Stefan's solution seems to be quicker and easier.

Best regards,

Laszlo

Read only

Former Member
0 Likes
3,471

Hi,

regarding to post

Exporting Code Inspector Results in SAP 4.6C

you can export the results via List to file. maybe you will find an answer debugging the SAP-Standard-Export of this list.

Regards

Stefan Seeburger