ABAP-code for converting string to xstring to string

Source: Internet
Author: User

Recently, some netizens asked about string to xstring to String Conversion. The following code is for your reference.

The Code is as follows:

Report zrich_0001.

Data: S type string,
H (1) Type X,
C (1) type C,
Byte (2) Type C,
Length type I,
Rochelle bindata type xstring,
L_cntbin type sdokcntbins.

Field-Symbols: <dummy>.

S = 'this is a string! '.
Length = strlen (s ).

* Use Write to convert string to xstring
Write:/'use write to convert string to xstring '.
Uline/1 (80 ).
New-line.
Do length times.
Byte = (sy-index-1 ).
C = S + byte (1 ).
* You can do this
Assign h to <dummy> type 'x '.
Write c to <dummy>.
Write: H.
Enddo.

* Use function to convert string to xstring
Call function 'scms _ string_to_xstring'
Exporting
TEXT = s
* Mimetype =''
Importing
Buffer = l_bindata
Exceptions
Failed = 1
Others = 2
.
If sy-subrc = 0.
Uline/1 (80 ).
Write:/'use function to convert string to xstring '.
Uline/1 (80 ).
Write:/l_bindata.
Endif.
*
** 1. Convert input-table to xstring
* Call function 'scms _ binary_to_xstring'
* Exporting: input_length = Length
* Importing: Buffer = l_bindata
* Tables: binary_tab = l_cntbin
* Exceptions: Failed = 1
* Others = 2.
* If sy-subrc <> 0.
* Endif.

 

* 2. Convert xstring to string
Clear length.
Call function 'scms _ xstring_to_binary'
Exporting:
Buffer = l_bindata
Importing:
Output_length = Length
Tables:
Binary_tab = l_cntbin.
If sy-subrc = 0.
Call function 'scms _ binary_to_string'
Exporting
Input_length = Length
Importing
Text_buffer = s
Output_length = Length
Tables
Binary_tab = l_cntbin
* Exceptions
* Failed = 1
* Others = 2
.
If SY-SUBRC <> 0.
Uline/1 (80 ).
Write:/'convert xstring to output-table '.
Uline/1 (80 ).
Write:/s.
Endif.
Endif.

 

3 decodeBase64(Type string) into plaintext (type string ).

Form encode_base64 using plaintext base64.
Check plaintext is not initial.
Constants:
Lc_op_enc Type X value 36.
Data:
L_len type I,
Rochelle xstr type xstring,
Lr_conv type ref to cl_abap_conv_out_ce.
Lr_conv = cl_abap_conv_out_ce => Create ().
L_len = strlen (plaintext ).
Lr_conv-> write (Data = plaintext n = l_len ).
L_xstr = lr_conv-> get_buffer ().
Call 'ssf _ abap_service'
Id 'opcode' field lc_op_enc
Id 'bindata' field l_xstr
Id 'b64data' field base64. "# EC ci_ccall
Endform.

 

 

Related functions

Scms_string_to_xstring

 

'Ecatt _ conv_xstring_to_string'

 

Scms_binary_to_xstring

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.