简体   繁体   中英

Question about special character(μm) for SAP and ABAP

Problem

I need to put some values into Z-table with unit, which are not in SAP standard(micron).

EDIT: I'm talking about 'μm' itself, not it's meaning - I made table which have 'unit' field, which are putting 'μm' inside that field, and 'value' field, which are int which have it's thickness - like, 30.

So I can use it to Report - like showing, 'this specific material have 30μm thickness'.

Question

I got that data from PI - which are sending that values from legacy system (might be unicode-based). I have to put that data, using ABAP, to my Z-table.

  1. Do I safe to set field type, Char length 2(like um, not μm )?

  2. How can I do comparision logic for special values [ex) If f1 = 'μm'.]

Any help will be appreciated!

The answer of the right length is answered in the documentation of Built-In Character-Like Types .

  • When specifying lengths for character-like types, note that the length of a character in bytes depends on the character representation used. For the character representation UCS-2 used by the ABAP programming language, the length of a character is two bytes.

Regarding UCS-2:

UCS-2

Two byte Unicode character representation. In this representation, all characters are represented by two bytes (16 bits). In UCS-2, 65536 different characters can be encoded, that correspond to the so called Basic Multilingual Plane (BMP) of the Unicode standard. In contrast to UTF-16, UCS-2 does not support characters from the surrogate area. The ABAP programming language supports UCS-2 in Unicode systems and therefore no surrogates.

DATA(lv_x) = '𓀀'. "C length 2
DATA(lv_y) = 'μ'. "C length 1

Since μ is present in the UC2-charset (00B5 MICRO SIGN), it will occupy one character in ABAP and can be stored and compared as such.
You might be able to change the character representation of a database table, but as soon as ABAP reads from it, it will be converted to UCS-2.

Reading a UTF-8 File with the content μm works just fine

cl_gui_frontend_services=>file_open_dialog( CHANGING file_table  = lt_files
                                                     rc          = lv_rc
                                                     user_action = lv_action ).
IF lv_action <> cl_gui_frontend_services=>action_ok OR lv_rc <> 1.
  RETURN.
ENDIF.

DATA lt_tab TYPE STANDARD TABLE OF string.
cl_gui_frontend_services=>gui_upload( EXPORTING filename = |{ lt_files[ 1 ]-filename }|
                                                filetype = 'ASC'
                                                codepage = '4110'
                                      CHANGING  data_tab = lt_tab ).
DATA(lv_text) = REDUCE string( INIT s = `` FOR <lv_line> IN lt_tab NEXT s = s && <lv_line> ).
DATA(lv_unit) = CONV zmy_units-unit( lv_text ).
INSERT zmy_units FROM @( VALUE zmy_units(
    unit        = lv_text
    description = 'Test' ) ).

SELECT SINGLE * FROM zmy_units WHERE unit = 'μm' INTO @DATA(ls_unit).
WRITE ls_unit-unit.
NEW-LINE.
WRITE |{ xsdbool( ls_unit-unit = 'μm' ) }|.

* Result
* μm
* X

More information regarding encoding via RFC can be found in Conversions in Accordance with the SAP Standard - Communication Using Remote Function Calls .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM