SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Преобразование HEX <-> CHAR



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
Garik
Специалист
Специалист



Joined: 11 Oct 2007
Posts: 60

PostPosted: Wed Oct 31, 2007 10:56 am    Post subject: Преобразование HEX <-> CHAR Reply with quote

Привет!
Какие есть функциональные модули в ABAP для преобразования кода ASCII в символ и обратно? На подобии строковых функции в других языках:
CHR(n) Возвращает строку с символом с заданным кодом.
HEX(n) Возвращают строку с шестнадцатеричным представлением целого числа n.
Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Wed Oct 31, 2007 3:58 pm    Post subject: Reply with quote

Если версия системы 4.7 и выше
Code:

CALL METHOD cl_abap_conv_in_ce=>uccp
  EXPORTING
    uccp = '000D'
  RECEIVING
    char = cr.


для более старых версии, например FM URL_ASCII_CODE_GET
Посмотрите его содержимое, использование ASSIGN ... CASTING
один из универсальных способов преобразования типов, даже в юникодной системе

Code:
FUNCTION url_ascii_code_get.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(TRANS_CHAR) TYPE  URL_CHAR
*"  EXPORTING
*"     VALUE(CHAR_CODE) TYPE  URL_CODE
*"----------------------------------------------------------------------

  FIELD-SYMBOLS:
    <critical_x>                        TYPE x.

  ASSIGN trans_char TO <critical_x> CASTING.
  WRITE <critical_x> TO char_code.
ENDFUNCTION.


на основании этого кода, можно сделать обратное преобразование:

Code:

DATA: v_char.
FIELD-SYMBOLS: <fs> TYPE x.
DATA: v_int1 TYPE INT4.

v_char =  'й'.
ASSIGN v_char TO <fs> CASTING TYPE X.
v_int1 = <FS>.

Write: / 'Char: ', v_char,
       / 'Hex : ', <fs>,
       / 'Int : ', v_int1.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.