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

Issue in removing garbage values from string in class

Former Member
0 Likes
3,049

Hi Experts,

I am facing some problem while reading XML attachment in class CL_DOCUMENT_BCS.

While reading contents_hex values I am getting garbage values like '0000000000000' at end of string.

I tried to convert the xstring values to string

and those values became '################################' .

But couldn't remove same using all standard process.

like

1) REPLACE all occurrences of '##' IN:

       lv_string WITH '  ' .

2) TRANSLATE lv_string  using  '##   '.

However if I copy same string to normal SE38 editor and apply above mentioned approach it works.

I searched relevant issues posted but couldn't find concrete solution for same.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,271

Hi Sandeep,

Try to use the method xstring_to_solix in CL_DOCUMENT_BCS to convert the xstring into string.Apply the replace occurance rule and try.

Regards,

Kannan

Hi Experts,

I am facing some problem while reading XML attachment in class CL_DOCUMENT_BCS.

While reading contents_hex values I am getting garbage values like '0000000000000' at end of string.

I tried to convert the xstring values to string

and those values became '################################' .

But couldn't remove same using all standard process.

like

1) REPLACE all occurrences of '##' IN:

       lv_string WITH '  ' .

2) TRANSLATE lv_string  using  '##   '.

However if I copy same string to normal SE38 editor and apply above mentioned approach it works.

I searched relevant issues posted but couldn't find concrete solution for same.

11 REPLIES 11
Read only

former_member185613
Contributor
0 Likes
2,271

Hi Sandeep,

Since it is the end of string, new line or horizontal tab is appearing as '#' values. Try the below code and see if it helps,

REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>CR_LF IN lv_string WITH space.

Regards,

~Athreya

Read only

0 Likes
2,271

Hi Athreya,

I have tried all below mentioned approach already.

REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN lv_string WITH space.

   CONDENSE lv_string.

   REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>newline IN lv_string WITH space.

   CONDENSE lv_string.

   REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>cr_lf IN lv_string WITH space.

   CONDENSE lv_string.

  REPLACE ALL OCCURRENCES OF  cl_abap_char_utilities=>vertical_tab IN lv_string WITH space.

   CONDENSE lv_string.

none of them removed the garbage values.

Regards,

Sandeep

Read only

Former Member
0 Likes
2,272

Hi Sandeep,

Try to use the method xstring_to_solix in CL_DOCUMENT_BCS to convert the xstring into string.Apply the replace occurance rule and try.

Regards,

Kannan

Read only

0 Likes
2,271

Hi Kannan,

Thnx for your reply.

But as I mentioned in my question I am getting this xstring by reading contents_hex values, which is a solix table only.

Read only

matt
Active Contributor
0 Likes
2,271

Go into debug and find out the hex values of the # characters.

Read only

0 Likes
2,271

Hi Mathew,

They are appearing as '0000000000000'. As I mentioned in my question.

Regards,

Sandeep

Read only

matt
Active Contributor
0 Likes
2,271

Right, so that is the hex value. This document explains how to remove the nulls.

Read only

0 Likes
2,271

Thnx a lot Matthew. It worked. However I am still clueless why Replace of all occurrence didn't work.

Read only

matt
Active Contributor
0 Likes
2,271

Because when you type # in the abap editor, that is 0x23 which isn't the same as the null char, 0x00.

Read only

0 Likes
2,271

Hi,

I'm glad you got the solution already, but if the correct attachment size (not including the hex nulls padded to the last entry of solix_tab, in other words) is known, I'd use CL_BCS_CONVERT=>SOLIX_TO_XSTRING( ).

cheers

Jānis

Read only

former_member272826
Discoverer
0 Likes
2,271

Hi, maybe for someone will be interesting also this simple approach to remove this "garbage" character from string:

method remove_garbage_character.
  data lv_white_characters type string.
  lv_white_characters = cl_abap_char_utilities=>get_simple_spaces_for_cur_cp( ).
  data: lv_lenght type i,
        lv_i type i value 0.
  lv_lenght = strlen( lv_white_characters ).
  while lv_i < lv_lenght.
    replace all occurrences of lv_white_characters+lv_i(1) in cv_string with ''.
    lv_i = lv_i + 1.
  endwhile.
endmethod.

CV_STRING is Changing parameter - TYPE String.

Enjoy, Z