UNICODE_Umstellung
www.4AP.de - ABAP Syntaxbeispiele:
Beispielcoding: Tools für UNICODE-Umstellung: (kopieren erlaubt aber auf eigene Gefahr :-))
Im folgenden einige Tools und Codingstrecken, die 'helfen'
REPORT Z_TN_STRUC_TO_CHAR_IN_UNICODE.
* bei der Umstellung von ABAP-Coding für
* UNICODE-Systeme gibt es oft das Problem,
* dass früher eine gemischte Struktur einfach
* mit einem MOVE in einen String überführt werden konnte.
* also z.B. CHAR2000 = structure. z.B. für IDOC-Daten.
* dieser Befehlt geht in UNICODE nur noch bei Strukturen
* die aus reinen Character-Feldern bestehen.
* Bei anderen muss jetzt mit ASSIGN ... CASTING gearbeitet werden.
DATA:
characterstring(500),
BEGIN OF mixed_structure,
string1(10),
packed TYPE p,
string2(18),
numc TYPE tage1, " (numc 4)
trenner type c,
datum type sy-datum,
trenner2 type c,
uzeit type sy-uzeit,
END OF mixed_structure.
* Struktur mit Werten füllen
mixed_structure-string1 = 'abcdefghij'.
mixed_structure-string2 = '1234567890.abcdefg'.
mixed_structure-numc = 1234.
mixed_structure-datum = sy-datum.
mixed_structure-uzeit = sy-uzeit.
mixed_structure-trenner = '_'.
mixed_structure-trenner2 = mixed_structure-trenner.
BREAK-POINT.
mixed_structure-packed = 9831155889.
* characterstring = mixed_structure. " DAS GEHT NICHT in Unicode
FIELD-SYMBOLS: <gib_mir_struc> TYPE c.
ASSIGN mixed_structure TO <gib_mir_struc> CASTING.
characterstring = <gib_mir_struc>.
WRITE characterstring.
Die Umwandlung eines Strings in eine Struktur kommt z.B. auch oft bei der IDOC-Verarbeitung vor. Dort liegen die Daten in einem DATA-Feld mit üblicherweise 2000 Character-Länge. Die ersten 18 Char die MATNR, dann 4 Char für die VKORG usw. Wenn jetzt nicht nur Characterfelder in der Struktur enthalten sind funktioniert ein einfacher MOVE unter Unicode nicht mehr.
** MOVE i_zsctapos-data TO i_strudv09.
* In Unicode muss gecasted werden
FIELD-SYMBOLS: <zppstdv09> TYPE zppstdv09.
ASSIGN i_zsctapos-data TO <zppstdv09> CASTING.
i_strudv09 = <zppstdv09>.
Ersetzen des Funktionsbausteines WS_DOWNLOAD (WS_UPLOAD geht analog dazu)
* CALL FUNCTION 'WS_DOWNLOAD'
* EXPORTING
* filename = p_zdat
* filetype = 'DAT'
* mode = c_true
* TABLES
* data_tab = it_result
* fieldnames = it_names
* EXCEPTIONS
* file_open_error = 1
* file_write_error = 2
* invalid_filesize = 3
* invalid_type = 4
* no_batch = 5
* unknown_error = 6
* invalid_table_width = 7
* gui_refuse_filetransfer = 8
* customer_error = 9
* OTHERS = 10.
DATA: lv_filename TYPE string.
lv_filename = p_zdat.
* Unicode: Methode statt Funktionsbaustein
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
* bin_filesize = bin_filesize
filename = lv_filename
filetype = 'DAT'
append = c_true
* write_field_separator = SPACE
* header = '00'
* trunc_trailing_blanks = SPACE
* write_lf = 'X'
* col_select = SPACE
* col_select_mask = SPACE
* dat_mode = SPACE
* confirm_overwrite = SPACE
* no_auth_check = SPACE
* codepage = SPACE
* ignore_cerr = ABAP_TRUE
* replacement = '#'
* write_bom = SPACE
* trunc_trailing_blanks_eol = 'X'
* wk1_n_format = SPACE
* wk1_n_size = SPACE
* wk1_t_format = SPACE
* wk1_t_size = SPACE
* show_transfer_status = 'X'
fieldnames = it_names
* write_lf_after_last_line = 'X'
* virus_scan_profile = '/SCET/GUI_DOWNLOAD'
* IMPORTING
* filelength = filelength
CHANGING
data_tab = it_result
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.
* ELSE.
* MESSAGE ID 'ZSC' TYPE 'I' NUMBER 208.
ENDIF.
* Aufruf Excel
** CALL FUNCTION 'WS_EXECUTE'
** EXPORTING
** commandline = p_zdat
** inform = ' '
** program = p_excel
** winid = space.
* Unicode: Methode statt Funktionsbaustein
DATA: lv_application TYPE string.
lv_application = p_excel.
CALL METHOD cl_gui_frontend_services=>execute
EXPORTING
document = lv_filename
application = lv_application
* parameter = parameter
* default_directory = default_directory
* maximized = maximized
* minimized = minimized
* synchronous = synchronous
operation = 'OPEN'
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
bad_parameter = 3
file_not_found = 4
path_not_found = 5
file_extension_unknown = 6
error_execute_failed = 7
synchronous_failed = 8
not_supported_by_gui = 9
OTHERS = 10.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Beim Ersetzen des Funktionsbausteines UPLOAD ist noch der File-Open-Dialog mit einzubauen:
* Umstellung von UPLOAD auf Methoden aus cl_gui_frontend_services
DATA: lt_file_table TYPE filetable,
ls_file_table LIKE LINE OF lt_file_table,
lv_filename TYPE string,
lv_rc TYPE i.
clear: lt_file_table, ls_file_table, lv_filename, lv_rc.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Bitte eine Datei auswählen:'
* default_extension =
default_filename = 'reis.nnn'
file_filter = 'NNN-Dateien(*.nnn)|*.nnn| Alle-Dateien(*.*)|*.*|'
* with_encoding =
initial_directory = 'X:\daten\sap\'
multiselection = abap_false
CHANGING
file_table = lt_file_table
rc = lv_rc
* user_action =
* file_encoding =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
others = 5.
IF sy-subrc <> 0 or lv_rc <> 1.
* Implement suitable error handling here
REJECT.
ENDIF.
* Jetzt die Datei laden
DATA: lt_data_tab1 LIKE STANDARD TABLE OF u1.
READ TABLE lt_file_table INTO ls_file_table INDEX 1.
lv_filename = ls_file_table-filename.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = lv_filename
filetype = 'ASC'
* has_field_separator = SPACE
* header_length = 0
* read_by_line = 'X'
* dat_mode = SPACE
* codepage = SPACE
* ignore_cerr = ABAP_TRUE
* replacement = '#'
* virus_scan_profile =
* IMPORTING
* filelength =
* header =
CHANGING
data_tab = lt_data_tab1
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. " AND cancel <> 'x'.
* APPEND u1.
MOVE lt_data_tab1[] TO u1[].
ELSE.
REJECT.
ENDIF.