‎2009 Mar 11 10:26 AM
Hello!
I've created a BSP-page to upload a file (types PDF, jpg, doc) and save it with a BO using GOS. Unfortunately I face a problem converting file-content xstring to string using class CL_ABAP_CONV_IN_CE. First I tried method CREATE with default-encoding, but in this case calling method READ raises exception CX_SY_CONVERSION_CODEPAGE. So I tried the following code: There is no exception, but I'm not able to open the saved document in the GOS of the BO. I assume that I'm using a wrong codepage.
CALL FUNCTION 'NLS_GET_FRONTEND_CP'
EXPORTING
langu = sy-langu
FETYPE = 'MS'
IMPORTING
frontend_codepage = lv_codepage
EXCEPTIONS
illegal_syst_codepage = 1
no_frontend_cp_found = 2
internal_or_db_error = 3
OTHERS = 4.
TRY.
lv_encoding = lv_codepage.
cl_abap_conv_in_ce=>create(
EXPORTING
encoding = lv_encoding
input = lv_file " Type XSTRING
RECEIVING
conv = conv
).
conv->read(
IMPORTING
data = file_content " Type STRING
).
CATCH cx_parameter_invalid_range .
CATCH cx_sy_codepage_converter_init .
CATCH cx_sy_conversion_codepage .
CATCH cx_parameter_invalid_type .
ENDTRY.
I'm looking forward to your hints!
Thanks in advance!
Greetings
Wolfgang
‎2009 Mar 11 10:34 AM
hi,
Check this code..
DATA convin TYPE REF TO cl_abap_conv_in_ce,
CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
encoding = 'UTF-8'
endian = 'L'
ignore_cerr = 'X'
replacement = '#'
input = l_buffer " Xstring
RECEIVING
conv = convin.
CALL METHOD convin->read
IMPORTING
data = l_data. " String
Edited by: Avinash Kodarapu on Mar 11, 2009 4:04 PM
‎2009 Mar 11 11:40 AM
Thanks for your promp reply!
Unfortunately your hint does not solve the problem. If I open the saved file in the BO the pdf viewer (acrobat) reports that the file my be damaged!
Debugging my code I found out that the generated string contains quite a lot # signs. I assume that many characters could not be converted and where replaced by #.
Greetings
Wolfgang
Addition: We are running a unicode-system!
Edited by: Wolfgang Brunneder on Mar 11, 2009 1:52 PM
‎2009 Mar 11 1:50 PM
Hi,
For this kind of convertion use FM HR_KR_XSTRING_TO_STRING . You will get rid of unwanted # marks when uploading the file.
Regards
Marcin
‎2009 Mar 11 3:41 PM
Hello Marcin!
Thanks for your reply! Can you tell me how I can find the correct codepage to pass to the function module?
Thanks!
Greetings Wolfgang
‎2009 Mar 11 5:38 PM
Hi Wolfgang,
You don't use any code page here. Just give your XSTRING in input and receive STRING on output. As you read the file byte by byte you don't need to worry about text convertion, as it is read excatly as it appears.
Regards
Marcin
‎2009 Mar 12 6:17 AM
Hi Marcin!
I've tried your hint, but it doesn't work. But now I found a working solution:
cl_abap_conv_in_ce=>create(
EXPORTING
encoding = 'NON-UNICODE'
endian = 'L'
RECEIVING
conv = conv
).
conv->convert(
EXPORTING
input = fileupload->file_content " type xstring
IMPORTING
data = file_content " type string
).
Thanks for your help! I rewarded some points!
Greetings Wolfgang
‎2009 Mar 11 2:09 PM
Hello,
May be the codepage retrieval is not correct. You can use this method to get the codepage & use your code:
DATA:
rc TYPE i VALUE 0,
v_encoding TYPE abap_encoding.
* Get the LOGON Encoding for the particular user
CALL METHOD cl_gui_frontend_services=>get_saplogon_encoding
CHANGING
rc = rc
file_encoding = v_encoding
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
cannot_initialize_globalstate = 4
OTHERS = 5.
IF sy-subrc <> 0 OR
v_encoding = 0.
CLEAR v_encoding.
ENDIF.Hope this helps.
BR,
Suhas
‎2009 Mar 11 2:18 PM
Thanks for your reply!
Unfortunately cl_gui_frontend_services=>get_saplogon_encoding doesn't work (sy-subrc = 3) - I assume because I'm working with BSP.