Hello,
Estoy intentando exportar un archivo de datos en codificación ISO-8859-15. Este tipo de código permite caracteres como €, Š, š, Ž, ž, Œ, œ o Ÿ.
He investigado las herramientas ABAP disponibles para este propósito, especialmente a través de este excelente
blog
de
sandra.rossi
.
Aquí puedes encontrar mi código de prueba:
*&---------------------------------------------------------------------*
*& Report ZBC_FILE_ENCODING
*&---------------------------------------------------------------------*
*& Encoding test report
*&---------------------------------------------------------------------*
REPORT zbc_file_encoding.
DATA: gv_file TYPE text255,
gt_file LIKE STANDARD TABLE OF gv_file,
gv_filename TYPE string,
gv_path TYPE string,
gv_fullpath TYPE string,
gv_bin_filesize TYPE i,
gt_bin_data TYPE solix_tab,
gv_xfile TYPE xstring,
gv_sfile TYPE string,
gv_sap_codepage TYPE cpcodepage,
gv_default_file_name TYPE string,
gv_external_name TYPE tcp00a-cpattr,
go_abap_conv_obj TYPE REF TO cl_abap_conv_obj,
gv_incode TYPE cpcodepage,
gv_outcode TYPE cpcodepage.
gv_file = 'A;B;C;é;€;Š;š;Ž;ž;Œ;œ;Ÿ'.
APPEND gv_file TO gt_file.
gv_file = 'D;E;F;é;€;Š;š;Ž;ž;Œ;œ;Ÿ'.
APPEND gv_file TO gt_file.
LOOP AT gt_file INTO gv_file.
CONCATENATE gv_sfile gv_file cl_abap_char_utilities=>cr_lf INTO gv_sfile.
ENDLOOP.
gv_external_name = 'ISO-8859-15'.
CALL FUNCTION 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
EXPORTING
external_name = gv_external_name
IMPORTING
sap_codepage = gv_sap_codepage
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'SCP_GET_CODEPAGE_NUMBER'
EXPORTING
database_also = ' '
IMPORTING
appl_codepage = gv_incode
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
gv_outcode = gv_sap_codepage.
CREATE OBJECT go_abap_conv_obj
EXPORTING
incode = gv_incode
outcode = gv_outcode
miss = 'S'
ctrlcode = '.'
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL METHOD go_abap_conv_obj->convert
EXPORTING
inbuff = gv_sfile
outbufflg = gv_bin_filesize
IMPORTING
outbuff = gv_xfile
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = gv_xfile
IMPORTING
output_length = gv_bin_filesize
TABLES
binary_tab = gt_bin_data.
CONCATENATE 'test_encoding_' gv_external_name '.csv' INTO gv_default_file_name.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_file_name = gv_default_file_name
CHANGING
filename = gv_filename
path = gv_path
fullpath = gv_fullpath
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = gv_bin_filesize
filename = gv_fullpath
filetype = 'BIN'
show_transfer_status = ' '
CHANGING
data_tab = gt_bin_data
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF
Lamentablemente, al final, no obtengo lo que esperaba:
Notepad++ dice que el formato es Windows-1252, los caracteres especiales están desordenados e incluso el retorno de carro y avance de línea no son reconocidos.
¿Alguna idea de qué estoy haciendo mal y cómo lograr mi objetivo?
Gracias de antemano por tu ayuda.
Saludos cordiales,
Marco Silva