Posted: Fri Jul 17, 2009 12:30 pm Post subject: Unicode преобразование типов C - X
Добрый день! Коллеги, кто имеет опыт переноса программ из неюникодных систем в юникодную, как исправить ошибку?
Quote:
"L_LINE" and "MS_CODES-CHAR_CODE" are type-incompatible
Code:
DATA: gt_lines TYPE TABLE OF line.
PERFORM convert_win1251_to_dos TABLES gt_lines.
*&---------------------------------------------------------------------*
*& Form convert_win1251_to_dos
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_LINES
*----------------------------------------------------------------------*
FORM convert_win1251_to_dos TABLES pt_lines.
DATA l_line TYPE line.
DATA:
BEGIN OF ms_codes,
dos1(33) TYPE x VALUE
'808182838485F0868788898A8B8C8D8E8F909192939495969798999B9A9C9D9E9F',
dos2(33) TYPE x VALUE
'A0A1A2A3A4A5F1A6A7A8A9AAABACADAEAFE0E1E2E3E4E5E6E7E8E9EBEAECEDEEEF',
win1(33) TYPE x VALUE
'C0C1C2C3C4C5A8C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DBDADCDDDEDF',
win2(33) TYPE x VALUE
'E0E1E2E3E4E5B8E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FBFAFCFDFEFF',
x1 TYPE x,
x2 TYPE x,
char_code TYPE x,
END OF ms_codes .
*-- Convert Process
LOOP AT pt_lines INTO l_line.
DO 256 TIMES VARYING ms_codes-char_code
FROM l_line NEXT l_line+1 .
DO 33 TIMES VARYING ms_codes-x1
FROM ms_codes-win1 NEXT ms_codes-win1+1
VARYING ms_codes-x2
FROM ms_codes-dos1 NEXT ms_codes-dos1+1.
IF ms_codes-char_code EQ ms_codes-x1.
ms_codes-char_code = ms_codes-x2.
EXIT.
ENDIF.
ENDDO.
DO 33 TIMES VARYING ms_codes-x1
FROM ms_codes-win2 NEXT ms_codes-win2+1
VARYING ms_codes-x2
FROM ms_codes-dos2 NEXT ms_codes-dos2+1.
IF ms_codes-char_code EQ ms_codes-x1.
ms_codes-char_code = ms_codes-x2.
EXIT.
ENDIF.
ENDDO.
ENDDO.
MODIFY pt_lines FROM l_line.
ENDLOOP.
Age: 165 Joined: 04 Oct 2007 Posts: 1218 Location: Санкт-Петербург
Posted: Fri Jul 17, 2009 2:01 pm Post subject:
Что касается конкретно этой ошибки, то ее можно устранить приведением типов через assign,
Code:
DATA: l_c(1).
FIELDS-SYMBOLS: <X_C> type x,
<X_X> type x.
...
DO 256 TIMES VARYING l_c
FROM l_line+0(1) NEXT l_line+1(1) RANGE l_line.
ASSIGN l_c TO <X_C> casting.
ASSIGN ms_codes-char_code TO <X_X> casting.
<X_X> = <X_C>.
но в целом, думаю, этот код не будет работать, потому что коды символов кирилицы (DOS или WIN) в однобайтовой кодировке и юникодной не совпадают, даже если вы решите использовать только младший байт. Поэтому вам придется или создавать новую таблицу соотвествия DOS <-> WIN, или, что на мой вгляд более правильно, делать преобразования методами встроенных классов:
CL_ABAP_CONV_IN_CE:
Reads data from a container and converts it to the system format. You can also fill structures with data.
CL_ABAP_CONV_OUT_CE:
Converts data from the system format to an external format and writes it to a container.
CL_ABAP_CONV_X2X_CE:
Converts data from one external format to another.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.