‎2009 May 22 11:59 AM
Hi gurus,
I have a PDF in binary format from a smartform and I need to encode it in base64 format.
I'm using cl_http_utility=>encode_base64 but it doesn't works.
Debugging my application, I've downloaded the binary file from the debugger and I can open it with a pdf reader. But if I put the conversion returnered from this method in a converter (base64 to binary) PDF Reader can't read my file.
Does anyone faced similar problem?
Thanks in advance.
Regards,
David Gimeno
‎2009 May 22 2:34 PM
hi
check this example:
REPORT ZTEST.
DATA: FILESIZE TYPE i.
DATA: CANCEL.
DATA: ACT_FILENAME LIKE RLGRAP-FILENAME.
DATA: EXTEMPL LIKE RLGRAP-FILENAME.
DATA: ACT_FILETYPE LIKE RLGRAP-FILETYPE.
DATA: BEGIN OF tab_imp occurs 0,
line(2000),
END OF tab_imp.
DATA: BEGIN OF jtab_imp occurs 0,
line(2000),
END OF jtab_imp.
DATA str1 type string.
DATA str2 type string.
DATA str3 type string.
DATA str type string.
start-of-selection.
*read binary file....
CALL FUNCTION 'UPLOAD'
EXPORTING
CODEPAGE = 'IBM'
FILETYPE = 'BIN'
FILEMASK_MASK = 'XLT'
IMPORTING
FILESIZE = FILESIZE
CANCEL = CANCEL
ACT_FILENAME = ACT_FILENAME
ACT_FILETYPE = ACT_FILETYPE
TABLES
DATA_TAB = tab_imp
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7.
check cancel is initial.
* convert binary table to string
loop at tab_imp into str.
concatenate str1 str into str1.
endloop.
* code string to base64
CALL METHOD cl_http_utility=>encode_base64
EXPORTING
UNENCODED = str1
RECEIVING
ENCODED = str2.
* decode string from base64
CALL METHOD cl_http_utility=>DECODE_BASE64
EXPORTING
ENCODED = str2
RECEIVING
DECODED = str3.
CALL FUNCTION 'CONVERT_STRING_TO_TABLE'
EXPORTING
I_STRING = str3
I_TABLINE_LENGTH = 2000
TABLES
ET_TABLE = jtab_imp.
* download file...
CALL FUNCTION 'DOWNLOAD'
EXPORTING
BIN_FILESIZE = FILESIZE
FILETYPE = 'BIN'
IMPORTING
ACT_FILENAME = ACT_FILENAME
TABLES
DATA_TAB = jtab_imp
EXCEPTIONS
INVALID_FILESIZE = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
CUSTOMER_ERROR = 7
OTHERS = 8.
regards,darek
‎2009 May 25 9:55 AM
Hi Darek,
Thanks for your reply but my code is similar than yours.
Finnaly I find a solution. The problem is on my PDF codepage. I put the following code instead of cl_http_utility=>encode_base64
CONSTANTS:
lc_op_enc TYPE x VALUE 36.
DATA:
l_len TYPE i,
l_xstr TYPE xstring,
lr_conv TYPE REF TO cl_abap_conv_out_ce.
lr_conv = cl_abap_conv_out_ce=>create( encoding = '4103' ).
l_len = STRLEN( i_plaintext ).
lr_conv->write( data = i_plaintext n = l_len ).
l_xstr = lr_conv->get_buffer( ).
CALL 'SSF_ABAP_SERVICE'
ID 'OPCODE' FIELD lc_op_enc
ID 'BINDATA' FIELD l_xstr
ID 'B64DATA' FIELD r_return.
Regards,
David.