Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- method save_xml_file.
- data: lt_itab_xml type standard table of char2048,
- lv_path type string,
- lv_filename type string,
- lv_path_2 type string,
- lv_file_encoding type string.
- lt_itab_xml = it_xml.
- lv_path = iv_path.
- "Вызываем диалог сохранения, если не указали путь вручную
- if lv_path is initial.
- cl_gui_frontend_services=>file_save_dialog(
- exporting
- window_title = 'Сохранение XML файла...'
- default_file_name = 'Заказ поставщику'
- file_filter = 'XML файл (*.xml)|*.xml'
- changing
- filename = lv_filename
- path = lv_path_2
- fullpath = lv_path
- exceptions
- cntl_error = 1
- error_no_gui = 2
- not_supported_by_gui = 3
- others = 4 ).
- if sy-subrc <> 0.
- message id sy-msgid type sy-msgty number sy-msgno
- with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
- endif.
- endif.
- " <<< Изменяем название кодировки в файле XML на "UTF-8" и получаем код этой кодировки
- "**************************************************************************************
- data: lv_sap_codepage type cpcodepage,
- lv_codepage type abap_encoding.
- field-symbols: <ls_itab_xml> like line of lt_itab_xml.
- "Это нужно что бы в файле XML стоял формат 'UTF-8', а не 'utf-16'.Хотя по факту он и так будет 'UTF-8'(ниже указываем его) почему так надо - ХЗ
- loop at lt_itab_xml assigning <ls_itab_xml>.
- replace first occurrence of substring 'utf-16' in <ls_itab_xml> with 'UTF-8' ignoring case.
- endloop.
- "Получим код кодировки 'UTF-8'
- call function 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
- exporting
- external_name = 'UTF-8'
- importing
- sap_codepage = lv_sap_codepage
- exceptions
- not_found = 1
- others = 2.
- if sy-subrc <> 0.
- message id sy-msgid type sy-msgty number sy-msgno
- with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
- endif.
- lv_codepage = lv_sap_codepage.
- "**************************************************************************************
- " >>> Изменяем название кодировки в файле XML на "UTF-8" и получаем код этой кодировки
- "Сохраняем файл
- if lv_path is not initial.
- call method cl_gui_frontend_services=>gui_download
- exporting
- filename = lv_path
- codepage = lv_codepage " или подставить код '4110' - это код для кодировки 'UTF-8'
- write_lf = abap_false " Не добавлять переводы строк после строки таблицы
- trunc_trailing_blanks = abap_true " Не добавлять пробелы после строк (для CHAR полей)
- changing
- data_tab = lt_itab_xml
- 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.
- endif.
- endmethod. "convert_data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement