Difference between revisions of "SAP ABAP XSTRING"
From SapWiki
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | ==Leer | + | ==Leer archivo de texto codificado UTF-8== |
− | ===Ejemplo 1=== | + | ===Ejemplo 1, como binario=== |
<nowiki> | <nowiki> | ||
DATA: lo_c2x TYPE REF TO cl_abap_conv_out_ce. | DATA: lo_c2x TYPE REF TO cl_abap_conv_out_ce. | ||
Line 27: | Line 27: | ||
ENDWHILE. | ENDWHILE. | ||
</nowiki> | </nowiki> | ||
− | ===Ejemplo 2=== | + | ===Ejemplo 2, como Binario=== |
<nowiki> | <nowiki> | ||
DATA l_string TYPE string. | DATA l_string TYPE string. | ||
Line 103: | Line 103: | ||
</nowiki> | </nowiki> | ||
− | == | + | ===Ejemplo 3, como ASC=== |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<nowiki> | <nowiki> | ||
CALL FUNCTION 'GUI_UPLOAD' | CALL FUNCTION 'GUI_UPLOAD' | ||
Line 154: | Line 132: | ||
if sy-subrc <> 0 . | if sy-subrc <> 0 . | ||
endif. | endif. | ||
+ | </nowiki> | ||
+ | ==string to xstring => xstring to string== | ||
+ | * ejemplo 1 | ||
+ | <nowiki> | ||
+ | lo_c2x = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ). | ||
+ | lo_c2x->convert( EXPORTING data = l_string | ||
+ | IMPORTING buffer = l_xstring ). | ||
+ | |||
+ | " convert xstring to string for output | ||
+ | cl_abap_conv_in_ce=>create( input = l_xstring )->read( IMPORTING data = l_string ). | ||
+ | </nowiki> | ||
+ | |||
+ | * ejemplo 2 | ||
+ | <nowiki> | ||
+ | l_xstring = cl_abap_codepage=>convert_to( source = l_string codepage = 'UTF-8' ). | ||
+ | |||
+ | CALL METHOD cl_http_utility=>if_http_utility~decode_utf8 | ||
+ | EXPORTING | ||
+ | encoded = l_xstring | ||
+ | RECEIVING | ||
+ | unencoded = l_string. | ||
</nowiki> | </nowiki> | ||
Line 160: | Line 159: | ||
Ejemplo: | Ejemplo: | ||
4110 - Unicode UTF-8 | 4110 - Unicode UTF-8 | ||
+ | 1100 - SAP internal, like ISO 8859-1 (00697/00819) | ||
==[[SAP_ABAP_VARIOS#Grabar_XSTRING_en_equipo_como_Binario(XML,PDF,etc.)|Grabar XSTRING en equipo como binario]]== | ==[[SAP_ABAP_VARIOS#Grabar_XSTRING_en_equipo_como_Binario(XML,PDF,etc.)|Grabar XSTRING en equipo como binario]]== |
Latest revision as of 20:45, 24 February 2021
Contents
Leer archivo de texto codificado UTF-8
Ejemplo 1, como binario
DATA: lo_c2x TYPE REF TO cl_abap_conv_out_ce. DATA l_string TYPE string. DATA l_string2 TYPE string. DATA l_xstring TYPE xstring. DATA l_filename TYPE string. CALL METHOD cl_faa_tenv_services=>gui_upload_xstring EXPORTING id_fullpath = l_filename IMPORTING ed_xstring = l_xstring. " convert xstring to string for output cl_abap_conv_in_ce=>create( input = l_xstring )->read( IMPORTING data = l_string ). WHILE l_string IS NOT INITIAL. SPLIT l_string AT cl_abap_char_utilities=>cr_lf INTO l_string2 l_string. IF NOT l_string2 CO cl_abap_char_utilities=>cr_lf. MOVE l_string2 TO it_entrada. APPEND it_entrada. ENDIF. ENDWHILE.
Ejemplo 2, como Binario
DATA l_string TYPE string. DATA l_string2 TYPE string. DATA l_xstring TYPE xstring. DATA l_filename TYPE string. DATA: l_filelength TYPE i. DATA: l_data_tab LIKE rcgrepfile OCCURS 10 WITH HEADER LINE. DATA: l_auth_filename LIKE authb-filename. DATA: l_lines TYPE i. l_filename = p_file. * upload the file CALL METHOD cl_gui_frontend_services=>gui_upload EXPORTING filename = l_filename filetype = 'BIN' * header_length = l_header_length IMPORTING filelength = l_filelength CHANGING data_tab = l_data_tab[] EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 not_supported_by_gui = 17 error_no_gui = 18 OTHERS = 19. IF sy-subrc <> 0 . ENDIF. CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' EXPORTING input_length = l_filelength * FIRST_LINE = 0 * LAST_LINE = 0 IMPORTING buffer = l_xstring TABLES binary_tab = l_data_tab EXCEPTIONS failed = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. *" convert xstring to string for output cl_abap_conv_in_ce=>create( input = l_xstring )->read( IMPORTING data = l_string ). * transformar string a tabla interna WHILE l_string IS NOT INITIAL. SPLIT l_string AT cl_abap_char_utilities=>cr_lf INTO l_string2 l_string. IF NOT l_string2 CO cl_abap_char_utilities=>cr_lf. MOVE l_string2 TO it_entrada. APPEND it_entrada. ENDIF. ENDWHILE.
Ejemplo 3, como ASC
CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = l_filename filetype = 'ASC' CODEPAGE = '4110' TABLES data_tab = it_entrada EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 OTHERS = 17. if sy-subrc <> 0 . endif.
string to xstring => xstring to string
- ejemplo 1
lo_c2x = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ). lo_c2x->convert( EXPORTING data = l_string IMPORTING buffer = l_xstring ). " convert xstring to string for output cl_abap_conv_in_ce=>create( input = l_xstring )->read( IMPORTING data = l_string ).
- ejemplo 2
l_xstring = cl_abap_codepage=>convert_to( source = l_string codepage = 'UTF-8' ). CALL METHOD cl_http_utility=>if_http_utility~decode_utf8 EXPORTING encoded = l_xstring RECEIVING unencoded = l_string.
Codepage encodings
- Ver Tabla TCP00 - Catálogo de code page SAP
Ejemplo:
4110 - Unicode UTF-8 1100 - SAP internal, like ISO 8859-1 (00697/00819)