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

Function 'HR_KR_XSTRING_TO_STRING'

Former Member
0 Likes
3,136

Hi,

I need to convert a hexadecimal value to String. Then, I used the following function module HR_KR_XSTRING_TO_STRING. However, what I get as result is: ###.

DATA:

in_xstring TYPE xstring,

out_string TYPE string.

in_xstring = '00020C'.

CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'

EXPORTING

  • FROM_CODEPAGE = '8500'

in_xstring = in_xstring

  • OUT_LEN =

importing

out_string = out_string.

write out_string. " Result: ###

Anyone knows, how can I do to se correctly this result?

Thanks in advance,

Regards,

Leo

Leitooo

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
1,879

Hi Leonardo,

This is because your hex value contains only special characters. As SAP uses unicode UTF-16 so in your byte sequence 00020C each "character" is stored in two bytes.

First: '00', second '02', third '0C'. These are all special ASCII characters, that's why they appear as ### after conversion.

Put correct byte value in xstring and you will get desired results. Example:


CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
  EXPORTING
    in_xstring = '302E3230'   "0.20"
  IMPORTING
    out_string = out_string.

write: out_string.

Regards

Marcin

8 REPLIES 8
Read only

Former Member
0 Likes
1,879

Hi,

*   Convert XString to String
    data: loc_conv type ref to CL_ABAP_CONV_IN_CE,
            loc_xstring type xstring,
            loc_string type string.
    CALL METHOD CL_ABAP_CONV_IN_CE=>CREATE
      EXPORTING
        INPUT       = loc_xstring
        ENCODING    = 'UTF-8'
        REPLACEMENT = '?'
        IGNORE_CERR = ABAP_TRUE
      RECEIVING
        CONV        = loc_CONV.

    TRY.
        CALL METHOD loc_CONV->READ
          IMPORTING
            DATA = loc_string.
      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.

Regards,

Sudheer

Read only

0 Likes
1,879

Hi Sudheer Junnuthula,

I tried with CL_ABAP_CONV_IN_CE but I still having same problem. I mean, value of LOC_STRING is equal than ###.

I can't fnd the way to see ### as decimal value. For example: 0.20

Do you have any idea about what can I do?

Thanks in advance for your help

Best Regards,

Leo

Read only

Former Member
0 Likes
1,879

HI,

Check this FM HR_RU_CONVERT_HEX_TO_STRING

Refer to this link..

Read only

0 Likes
1,879

Hi Avinash Kodarapu,

I tried to solve my problem with your suggestion but it didn't work. I mean, it continues showing ### instead 0.20.

Do you have any idea about what can I do?

Thanks in advance.

Best Regards,

Leo

Read only

MarcinPciak
Active Contributor
1,881

Hi Leonardo,

This is because your hex value contains only special characters. As SAP uses unicode UTF-16 so in your byte sequence 00020C each "character" is stored in two bytes.

First: '00', second '02', third '0C'. These are all special ASCII characters, that's why they appear as ### after conversion.

Put correct byte value in xstring and you will get desired results. Example:


CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
  EXPORTING
    in_xstring = '302E3230'   "0.20"
  IMPORTING
    out_string = out_string.

write: out_string.

Regards

Marcin

Read only

0 Likes
1,879

Hi Marcin,

Thanks for your answer. In fact, you are right. However, my main problem is that I receive a file created in 4.6c version, which include these characters ### (00020C).

In this version (4.6c), I can move these characters to a dec field without problems. In fact, I see then its value like 0.20.

On the other hand, if I use the same file in ECC 6.0, I can't assign these characters to a dec field. Even by using functions/methods.

Is there any way to convert these character to dec value?

Anyways, thanks for your help. It has been quite useful.

Regards,

Leo

Read only

0 Likes
1,879

Hi,

The Value of 00020C is

00 - Null

02 - Start of text

0C - Form Feed .. so it is converting these values as #..

You need to use the FM and get the char value of these hexa values and using this replace the values with space.

Read only

0 Likes
1,879

Can you please explain how do I replace these 00 (Nulls) which has automatically been inserted after each and every character for a working 4.5B file which fails in ECC6?

Thanks in advance.

Regards,

BGaurav