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

Conversion Unicode to Windows-1251



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Conversion
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Wed Dec 09, 2009 3:39 pm    Post subject: Conversion Unicode to Windows-1251 Reply with quote

Code:
data: encoding                    type string.
  encoding = 'utf-8'.
  data: codepage            type cpcodepage.
 
  call function 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
    exporting
      external_name = encoding
    importing
      sap_codepage  = codepage
    exceptions
      not_found     = 1
      others        = 2.
 
  data: codepage2            type cpcodepage.
  encoding = 'windows-1251'.
  call function 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
    exporting
      external_name = encoding
    importing
      sap_codepage  = codepage2
    exceptions
      not_found     = 1
      others        = 2.
 
  data: length    type i,
          str TYPE string.
 
  length = strlen( string ).
  call function 'SCP_TRANSLATE_CHARS'
    exporting
      inbuff           = str
      inbufflg         = length
      incode           = codepage
      outcode          = codepage2
      substc_space     = 'X'
    importing
      outbuff          = str
    exceptions
      invalid_codepage = 1
      internal_error   = 2
      cannot_convert   = 3
      fields_bad_type  = 4
      others           = 5.


Code:
data: F_XTAB like SDOKCNTBIN occurs 1 with header line.
data: F_SIZE type I.
data: F_VALUE(120).
data: HX(2) type X value '0D0A'.
data: G_STRING type STRING.
data: G_BUFFER type XSTRING.
data: GCL_CONV_TO_X type ref to CL_ABAP_CONV_OUT_CE.

G_STRING = F_VALUE.
call method CL_ABAP_CONV_OUT_CE=>CREATE
  exporting
    ENCODING = '1504'
  receiving
    CONV     = GCL_CONV_TO_X.

call method GCL_CONV_TO_X->WRITE
  exporting
    DATA = G_STRING.

call method GCL_CONV_TO_X->GET_BUFFER
  receiving
    BUFFER = G_BUFFER.

concatenate G_BUFFER HX into G_BUFFER in byte mode.

call function 'SCMS_XSTRING_TO_BINARY'
  exporting
    BUFFER               = G_BUFFER
importing
   OUTPUT_LENGTH         = F_SIZE
  tables
    BINARY_TAB           = F_XTAB.
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 -> Programming Techniques | Приемы программирования -> Conversion 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.