Текущее время: Пн, июн 23 2025, 08:15

Часовой пояс: UTC + 3 часа


Правила форума


ВНИМАНИЕ!

Вопросы по SAP Query и Quick View - сюда



Начать новую тему Ответить на тему  [ Сообщений: 2 ] 
Автор Сообщение
 Заголовок сообщения: И снова кодировка UTF-8
СообщениеДобавлено: Пн, май 27 2013, 16:58 
Младший специалист
Младший специалист

Зарегистрирован:
Пн, ноя 07 2011, 11:46
Сообщения: 83
Добрый день, уважаемые коллеги!

Данная тема есть продолжение темы 'Выгрузить файл с кодировкой UTF-8'.
Итак, необходимо было выгрузить файл в кодировке UTF-8. Для этого мне было предложено конвертировать в UTF-8, а потом выгружать как бинарник. В UTF конвертировать классом cl_abap_conv_in_ce.
Для этого был написан код, который, к сожалению, падает в дамп(но дамп происходит в определённой системе! В других системах код работает корректно! Само описание дампа после кода):

TYPE-POOLS: abap.
TYPES:
BEGIN OF ty_string,
data TYPE string,
END OF ty_string.
DATA :
it_string TYPE STANDARD TABLE OF ty_string,
wa_string TYPE ty_string.
DATA:
v_string TYPE string,
v_xsrting TYPE xstring,
v_len TYPE i,
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.
CHECK v_encoding IS NOT INITIAL.
* Attribute for UTF-8 format
v_xsrting = cl_abap_char_utilities=>byte_order_mark_utf8.

DATA: v_conv TYPE REF TO cl_abap_conv_in_ce.
* Create a Conversion Instance
v_conv = cl_abap_conv_in_ce=>create(
encoding = v_encoding
input = v_xsrting ).

v_conv->read( IMPORTING data = v_string ). <------------ непосредственно тут происходит дамп

LOOP AT lt_data INTO ls_data.
IF sy-tabix = 1.
* To download a file in UTF-8 add the contents of BOM
* UTF8 infront of the first record.
CONCATENATE v_string ls_data INTO wa_string-data.
APPEND wa_string TO it_string.
ELSE.
MOVE ls_data TO wa_string-data.
APPEND wa_string TO it_string.
ENDIF.
ENDLOOP.

* Download the file
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = 'C:\Documents and Settings\...'
codepage = v_encoding
CHANGING
data_tab = it_string
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
.......
OTHERS = 24.


ОПИСАНИЕ ДАМПА:
Short text
A character set conversion is not possible.



What happened?
At the conversion of a text from codepage '1504' to codepage '1500':

- a character was found that cannot be displayed in one of the two
codepages;
- or it was detected that this conversion is not supported

The running ABAP program 'CL_ABAP_CONV_IN_CE============CP' had to be
terminated as the conversion
would have produced incorrect data.

The number of characters that could not be displayed (and therefore not
be converted), is 1. If this number is 0, the second error case, as
mentioned above, has occurred.



Error analysis
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_CONVERSION_CODEPAGE', was not
caught in
procedure "STORE" "(FORM)", nor was it propagated by a RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
Characters are always displayed in only a certain codepage. Many
codepages only define a limited set of characters. If a text from a
codepage should be converted into another codepage, and if this text
contains characters that are not defined in one of the two codepages, a
conversion error occurs.

Moreover, a conversion error can occur if one of the needed codepages
'1504' or '1500' is not known to the system.

If the conversion error occurred at read or write of screen, the file
name was ' '. (further information about the file: " ")

P.s. кодировка 1504 в таблице TCP00A есть, если указать кодировку 1500, то дампа нет. В чём возможная проблема? Мне кажется, что это проблема настройки, но как её описать, чтобы базис её исправил?


Пометить тему как нерешенную
Вернуться к началу
 Профиль Отправить email  
 
 Заголовок сообщения: Re: И снова кодировка UTF-8  Тема решена
СообщениеДобавлено: Вт, май 28 2013, 05:20 
Специалист
Специалист

Зарегистрирован:
Чт, мар 25 2010, 09:02
Сообщения: 207
Как то не так всё...

Попробуйте:
Code:
  data: out_str type string value 'Проверка! ©'.
  data: bin_data type xstring.

  data: lo_converter type ref to cl_abap_conv_out_ce.

*try.
  call method cl_abap_conv_out_ce=>create
    exporting
      encoding = '4110'
    receiving
      conv     = lo_converter.
* catch cx_parameter_invalid_range .
* catch cx_sy_codepage_converter_init .
*endtry.

*try.
  call method lo_converter->convert
    exporting
      data   = out_str
    importing
      buffer = bin_data.
* catch cx_sy_codepage_converter_init .
* catch cx_sy_conversion_codepage .
* catch cx_parameter_invalid_type .
*endtry.

  concatenate cl_abap_char_utilities=>byte_order_mark_utf8 bin_data into bin_data in byte mode.

  types: lt_x_row_type(100) type x.
  data: lt_bin_data type standard table of lt_x_row_type.
  data: lv_bin_data_len type i.

  call function 'SCMS_XSTRING_TO_BINARY'
    exporting
      buffer        = bin_data
    importing
      output_length = lv_bin_data_len
    tables
      binary_tab    = lt_bin_data.


call method cl_gui_frontend_services=>gui_download
  exporting
    bin_filesize              = lv_bin_data_len
    filename                  = 'D:\tmp\tst.txt'
    filetype                  = 'BIN'
  changing
    data_tab                  = lt_bin_data
*  exceptions
*    file_write_error          = 1
*    no_batch                  = 2
*    gui_refuse_filetransfer   = 3
*    invalid_type              = 4
*    no_authority              = 5
*    unknown_error             = 6
*    header_not_allowed        = 7
*    separator_not_allowed     = 8
*    filesize_not_allowed      = 9
*    header_too_long           = 10
*    dp_error_create           = 11
*    dp_error_send             = 12
*    dp_error_write            = 13
*    unknown_dp_error          = 14
*    access_denied             = 15
*    dp_out_of_memory          = 16
*    disk_full                 = 17
*    dp_timeout                = 18
*    file_not_found            = 19
*    dataprovider_exception    = 20
*    control_flush_error       = 21
*    not_supported_by_gui      = 22
*    error_no_gui              = 23
*    others                    = 24
        .
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.


Номер кодировки UTF8 - 4110. Да и в том сообщении кажется ошиблись, правильный класс cl_abap_conv_out_ce


Пометить тему как нерешенную
Вернуться к началу
 Профиль Отправить email  
 
Показать сообщения за:  Поле сортировки  
Начать новую тему Ответить на тему  [ Сообщений: 2 ] 

Часовой пояс: UTC + 3 часа


Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей


Вы не можете начинать темы
Вы не можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете добавлять вложения

Найти:
Перейти:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Русская поддержка phpBB