Application Development and Automation 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: 
Read only

raw data to string

Former Member
0 Likes
7,921

Hello All,

How can i convert a RAW data type to STRING or

Character type.

I tried using Move statement, but it didn't work.

I have a RAW data like this

323030313038303130303030303036383532 i need to extract

alternative digits from this. The result should be

200108010000006852.

I tried replace statement but it is deleting all 3's

other than the alternative ones.

please do help me.

Thanking you,

Suman

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,642

Hi,

Check this ..

DATA:
      convin        TYPE REF TO cl_abap_conv_in_ce,
      l_data        TYPE string,
      l_buffer       TYPE xstring.

  CALL METHOD cl_abap_conv_in_ce=>create
    EXPORTING
      encoding    = 'UTF-8'
      endian      = 'L'
      ignore_cerr = 'X'
      replacement = '#'
      input       = l_buffer         " pass Raw data
    RECEIVING
      conv        = convin.

  CALL METHOD convin->read
    IMPORTING
      data = l_data.               " Converted data

5 REPLIES 5
Read only

Former Member
0 Likes
2,642

Hi,

u can use the offset concept over here.

Take the total length in a variable.

Then perform do ...enddo till we meet the length.

And concatenate the alternative digits in a new variable......

Plz reply if u want sm more help.....

regards,

ajit.

Read only

awin_prabhu
Active Contributor
0 Likes
2,642

Hi Suman,

Check this logic.

REPORT ztest.

DATA: s(40) VALUE '323030313038303130303030303036383532',

l TYPE i,

d TYPE string,

r TYPE i VALUE 1.

l = STRLEN( s ).

l = l / 2.

DO l TIMES.

CONCATENATE d s+r(1) INTO d.

r = r + 2.

ENDDO.

write:/ d.

Thanks.

Read only

anuj_srivastava
Active Participant
0 Likes
2,642

Hi ,

Try this ..this will solve ur problem

data : str(40) type c.

data : l type i.

data : f type c.

data : m type i.

data : f1(40) type c.

str = '323030313038303130303030303036383532'.

l = strlen( str ).

do l times.

if l < m.

exit.

endif.

clear f.

m = m + 1.

f = str+m(1).

m = m + 1.

concatenate f1 f into f1 .

enddo.

write : f1.

Regards,

Anuj

Read only

Former Member
0 Likes
2,643

Hi,

Check this ..

DATA:
      convin        TYPE REF TO cl_abap_conv_in_ce,
      l_data        TYPE string,
      l_buffer       TYPE xstring.

  CALL METHOD cl_abap_conv_in_ce=>create
    EXPORTING
      encoding    = 'UTF-8'
      endian      = 'L'
      ignore_cerr = 'X'
      replacement = '#'
      input       = l_buffer         " pass Raw data
    RECEIVING
      conv        = convin.

  CALL METHOD convin->read
    IMPORTING
      data = l_data.               " Converted data

Read only

Former Member
0 Likes
2,642

Try to code like below

DATA : lv1(250) TYPE c VALUE '323030313038303130303030303036383532',

lv2(250) TYPE c,

lv3,

lv_strlen TYPE i,

lv_offset TYPE i.

lv_strlen = STRLEN( lv1 ).

lv_offset = 1.

DO lv_strlen TIMES.

lv3 = lv1+lv_offset(1).

CONCATENATE lv2 lv3 INTO lv2.

lv_offset = lv_offset + 2.

CLEAR : lv3.

IF lv_offset GE lv_strlen.

EXIT.

ENDIF.

ENDDO.

WRITE : lv2.

Hope it helps!!

Regards,

pavan