반응형
DATA: V_ABAP_ENCOD TYPE ABAP_ENCODING VALUE '4103',
V_CPCODEPAGE TYPE CPCODEPAGE VALUE '4103'.
DATA: V_X2(2) TYPE X,
V_XSTR TYPE XSTRING,
V_XSTR2 TYPE XSTRING.
DATA: V_STR TYPE STRING,
V_STR2 TYPE STRING.
*&---------------------------------------------------------------------*
*& SELECTION-SCREEN
*&---------------------------------------------------------------------*
PARAMETERS: P_TEXT TYPE STRING DEFAULT 'ABCD@#$會仔细观察FDGHERRGG*&<>找到DFDFDF'.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
"get codepage of the language, instead of hardcode the codepage
CALL FUNCTION 'SCP_CODEPAGE_FOR_LANGUAGE'
EXPORTING
LANGUAGE = sy-langu
IMPORTING
CODEPAGE = V_CPCODEPAGE.
V_ABAP_ENCOD = V_CPCODEPAGE.
"print out the original input string
WRITE: / 'Input string =', P_TEXT.
"firstly convert the string to binary per language codepage
v_xstr = CL_BCS_CONVERT=>STRING_TO_XSTRING( EXPORTING IV_STRING = P_TEXT IV_CODEPAGE = V_ABAP_ENCOD ).
CHECK V_XSTR IS NOT INITIAL.
DO.
V_X2 = V_XSTR. "get 2 bytes of data in string (under unicode, each char stored by 2 bytes)
V_XSTR2 = V_X2.
"here just to convert back the binary back to string under same codepage
"to test the conversion is correct
V_STR = CL_BCS_CONVERT=>XSTRING_TO_STRING( EXPORTING IV_XSTR = V_XSTR2 IV_CP = V_CPCODEPAGE ).
IF V_X2+1(1) = '00'. "as ASCII only require 1 byte encoding, the 2nd byte always 00
WRITE: / V_STR, '=>', V_X2, 'ASCII'.
ELSE.
WRITE: / V_STR, '=>', V_X2, 'Non-ASCII'.
ENDIF.
"here just to reconstruct the input string (string->binary->string) to check correctness
V_STR2 = V_STR2 && V_STR.
"shift 2 bytes for getting next character
SHIFT V_XSTR BY 2 PLACES LEFT IN BYTE MODE.
IF V_XSTR IS INITIAL.
EXIT.
ENDIF.
ENDDO.
"print out the reconstructed string
WRITE: / 'Reconstructed string =', V_STR2.
output
How to find whether char value is Chinese or not in the Unicode system? | SAP Community
반응형
'IT WORK > SAP FI and ABAP' 카테고리의 다른 글
[FI] Message ID나 Number로 유효성확인/대체 단계 찾는 방법 (0) | 2023.11.09 |
---|---|
[ABAP] 테이블명으로 티코드 찾기 How to find TCODE with Table name (0) | 2023.09.15 |
[SAP FI] FBV0: Error 00 349 for customer fields (0) | 2023.07.26 |
[SAP GUI] F4 Possible Entry 오류 - 내부 오류 : 테이블 포맷 F4 Possible Entry Error -Internal Error: Table format (0) | 2023.07.26 |
[ABAP] Unicode 관련 if_http_client->get_cdata 한글 깨짐 (0) | 2023.07.26 |