Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to pass the line feed character in the string to have its hex value?

Madhurivs23
Participant
0 Kudos

Hi,

I have a code below. Its converting character to its hex value. Now I want to passa line feed to the string. What character I should provide in the string variable so that it will convert to the line fees hex value?


data: hexstring type xstring,
     input     type string ,
     input_x type x length 49.
data: buffer type xstring,
     int    type i value 258,
     text(64) type c ,
     n     type sy-index,
     conv   type ref to cl_abap_conv_out_ce,
     loc_conv type ref to cl_abap_conv_in_ce.

*---convert into hexa decimals.
input = 'ABC123        ACHDA0000        C000000000'.
text = input.
n = strlen( text ).
conv = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' endian = 'L' ).
call method conv->write( data = text n = n ).
call method conv->write( data = int ).
buffer = conv->get_buffer( ).
*write : / buffer.
input_x = buffer.
break-point.
*---convert xstring to string.
call method cl_abap_conv_in_ce=>create
 exporting
   input       = input_x "buffer
   encoding    = 'UTF-8'
   replacement = '?'
   ignore_cerr = abap_true
 receiving
   conv        = loc_conv.
try.
   call method loc_conv->read
     importing
       data = input.
 catch cx_sy_conversion_codepage.
*-- Should ignore errors in code conversions
 catch cx_sy_codepage_converter_init.
*-- Should ignore errors in code conversions
 catch cx_parameter_invalid_type.
 catch cx_parameter_invalid_range.
endtry.


write:/ input_x.
write:/ input.

1 REPLY 1

Madhurivs23
Participant
0 Kudos

solved by myself:


data: hexstring type xstring,
     input     type string ,
     INPUT_c(132)   TYPE C,
     input_x type x length 66.

data: buffer type xstring,
     int    type i value 258,
     text(64) type c ,
     n     type sy-index,
     conv   type ref to cl_abap_conv_out_ce,
     loc_conv type ref to cl_abap_conv_in_ce.

*---convert into hexa decimals.
input = 'LOGDXNC00      DX009847  ACHDA000000000        C0000000000000000'.
text = input.
n = strlen( text ).
conv = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' endian = 'L' ).
call method conv->write( data = text n = n ).
call method conv->write( data = int ).
buffer = conv->get_buffer( ).
*write : / buffer.
input_x = buffer.
break-point.
*---convert xstring to string.
call method cl_abap_conv_in_ce=>create
 exporting
   input       = input_x "buffer
   encoding    = 'UTF-8'
   replacement = '?'
   ignore_cerr = abap_true
 receiving
   conv        = loc_conv.
try.
   call method loc_conv->read
     importing
       data = input.
 catch cx_sy_conversion_codepage.
*-- Should ignore errors in code conversions
 catch cx_sy_codepage_converter_init.
*-- Should ignore errors in code conversions
 catch cx_parameter_invalid_type.
 catch cx_parameter_invalid_range.
endtry.


write:/ input_x.
INPUT_C = INPUT_X.
SHIFT INPUT_C BY 4 PLACES RIGHT.
CONDENSE INPUT_C.
CONCATENATE INPUT_C '0A0D' INTO INPUT_C.
INPUT_X = INPUT_c.

write: /  input_x.


write:/ input_C.