cancel
Showing results for 
Search instead for 
Did you mean: 

Store pdf from ArchiveLink (binary) down to Netweaver file system

Former Member
0 Kudos

Hello!

I have a problem: I need to extract a pdf-file which is stored in table TOA01 in binary format. The pdf should be generated and stored into a pdf-file in the file system of the Netweaver application server.

The main problem: Whenever I extract the data from the table and write it down to a file, the data in the pdf-file is corrupted. I tried all kinds of convertation routines (OFT to Binary, OTF to XString, Binary to XString,...)

Can anybody help me with my problem? I need a pdf from the ArchiveLink table as a file on the filesystem.

Thank you for your help!

Best regards,

Markus

Accepted Solutions (1)

Accepted Solutions (1)

OttoGold
Active Contributor
0 Kudos

That probably means you need to use some "neutral" data type. Maybe XSTRING, RAWSTRING, RAW or X type could help.

I have check the mentioned function 'SCMS_AO_TABLE_GET' and it returns the tabl1024 type what is internally RAW type. Maybe you can just concatenate these values into some RAW or XSTRING. Or maybe some conversion? (like SCMS_STRING_TO_BINARY etc. but I son´t think so, you get the binary data from the function and should write the binary data as well).

For the inspiration check for the CL_PDFVIEWER in your SAP system which can be used for a PDF display there (or somewhere else) you can see how to handle the XSTRINGs, RAW etc.

Otto

Former Member
0 Kudos

Hello Otto!

I checked your suggestion but RAW or XSTRING cannot be written into a Dataset. Only binary or STRING-data is valild. In the meantime I conceive another suspicion what causes the error:

In the functiion module "SCMS_BINARY_TO_STRING" it is possible to hand over an encoding type. The only problem is that I couldn't find any programme type which uses this import parameter... I also don't know what type this parameter may be. I tried 'UTF-8' but this caused a shortdump and it seems as if a number should be transported in this parameter.

@all:

I would be very happy if anybody here could tell me what parameters are allowed for the encoding parameter of this module...

Best regards and a nice weekend to everybody,

Markus

Sandra_Rossi
Active Contributor
0 Kudos

That was almost correct. Use SCMS_BINARY_TO_XSTRING instead of SCMS_BINARY_TO_STRING:


DATA l_xstring TYPE xstring.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
     EXPORTING
       input_length       = filesize
     IMPORTING
       buffer             = l_xstring
     TABLES
       binary_tab         = lt_data
     EXCEPTIONS
       failed             = 1
       OTHERS             = 2.
ASSERT sy-subrc = 0.
OPEN DATASET lv_pdf FOR OUTPUT IN BINARY MODE.
IF sy-subrc = 0.
transfer l_xstring TO lv_pdf.
ELSE.
RAISE error_writing_file.
ENDIF.
CLOSE DATASET lv_pdf.

Former Member
0 Kudos

Hello Sandra!

thank you so much! Now the file on the Server seems to be correct. The checksum of the file is exactly the same a s the sum of the testfile. Now I only need to download the file from the server in the correct encoding version. I'll try...

But I think I did another big step and the solution seems to be in sight.

Have a nice day, Sandra.

Best regards!

Markus

Answers (3)

Answers (3)

OttoGold
Active Contributor
0 Kudos

IMHO you should use 'BIN' download which needs no encoding. Otto

OttoGold
Active Contributor
0 Kudos

What is that dataset you insist on? Why don´t you use come common way how to save a file? Otto

OttoGold
Active Contributor
0 Kudos

Hello,

you have two options from my point of view:

1) find somebody who can tell you what is the archivelink doing with the binary stream of data (that means how to convert it to the previous state)

2) find for yourself: I would create a simple print form, the result is of course PDF (you need to set GETPDF = 'X'), or better to say the result is the binary data stream. you will save this form into the archive link and then load it again and compare it with the stream you get right from the printing function

BTW: have you tried in other forums or have tried to do a search, if the problem has a public solution somewhere?

If this is the first somebody wants to do this (hard to believe), then it would be cool to write a contribution or a wiki about it. I guess I may use such a howto one day.

have a nice day, Otto

Former Member
0 Kudos

Hello Otto!

thanks for your help. I compared the input- und the output-data now and discovered, that the data is identically. The problem which causes my problem, lies in the writing of the data into the file by dataset.

First, I extract my pdf binary data from database table with the following function module.

CALL FUNCTION 'SCMS_AO_TABLE_GET'

EXPORTING

arc_id = ls_toa01-archiv_id

doc_id = ls_toa01-arc_doc_id

comp_id = 'data'

IMPORTING

length = filesize

TABLES

data = lt_data

EXCEPTIONS

error_http = 1

error_archiv = 2

error_kernel = 3

error_config = 4

OTHERS = 5.

IF sy-subrc <> 0.

RAISE error_retrieving_file.

ENDIF.

The result of this operation is stored in lt_data and seems to be correct. I compared the filesize of a pdf which I downloaded from GUI and lt_data. The size is exactly the same amount of bytes.

This is the coding part which doesn't work properliy is the following:

OPEN DATASET lv_pdf FOR OUTPUT IN BINARY MODE.

IF sy-subrc = 0.

LOOP AT lt_data INTO ls_data.

transfer ls_data TO lv_pdf.

ENDLOOP.

ELSE.

RAISE error_writing_file.

ENDIF.

CLOSE DATASET lv_pdf.

When the data is written into the dataset, the resulting file is corrupted in a certain way. I compared the binary content of both files, the correct one and the file created with the dataset part and discovered, that the data is identically. Only some line breaks are different. The result of this little differences is a blank pdf file instead of the correct one with text. Seems like really every single bit position has to be identically to the working pdf. If there is one space in the file too much or one line break, the pdf is corrupted.

Can anybody help me and describe how to create a pdf file out of an internal table?

Best regards,

Markus