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: 

Problem with cheking a # value in IF statement

former_member242512
Participant
0 Kudos

Hi ,

I have to check value of

val_tab  = node->get_value( ).
     do .
----
end do .

if my val_tab contains '#' or '##' a DO statement below it shoul not get executed . i tried IF with string operations but

its not working . it does not check it for '#' value . Plz help how can i check it .

9 REPLIES 9

MarcinPciak
Active Contributor
0 Kudos

Apparently the text mark behind this # is not encoded correclty, therefore it is shown this way.

It must be some special character most likely from 0-31 ASCII. If you don't know which one you can check if it is not one of them. To get string representation of that ASCII char use fm

HR_KR_XSTRING_TO_STRING i.e passing 'OD' - 31 DEC (line feed ) as input parameter. Then compare this ouput string with you # mark. Do the same for rest of the 0-31 ASCII chars.

This should help.

Regards

Marcin

0 Kudos

hi im getting dump incompatible type when i passed val_tab as input to line feed .

what should be the input .

0 Kudos

Try this logic


data: i type i,
      x type x,
      xstr type xstring,
      out_str type string,
      mark type string VALUE '#'.  "let's say your mark is here

do 31 times.
  xstr = x = sy-index. "convert to hex value and then to xstring
  CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
    EXPORTING
     in_xstring          = xstr
   IMPORTING
     OUT_STRING          = out_str.
 if out_str = mark.
   write: 'I found it'.
 endif.
enddo.

Your val_tab is probably of table type, right? You can't compare entire table with single mark. What you are excatly comparing, how does your IF condition look like?

Regards

Marcin

former_member242512
Participant
0 Kudos

hi ,

my val_tab is of type string . i just only want to check whether it contains a '#' .

if val_tab+0(1) ne '#' .
    .......
........
endif .

even though val_tab+0(1) contains a '#' the statements after IF is executed and not else .

0 Kudos

Hello Ujjwal,

The '#' symbol is nothing but a garbage character. I am quite sure the 2 '#' must be for CR_LF.

You can use the attribute CL_ABAP_CHAR_UTILITIES=>CR_LF instead of '#'.

I hope you get the catch.

BR,

Suhas

PS: You can refer to the class CL_ABAP_CHAR_UTILITIES for further details !!

I also faced the same problem as yours & this is how i solved it: [http://wiki.sdn.sap.com/wiki/display/ABAP/UploadXMLfiletointernaltable|http://wiki.sdn.sap.com/wiki/display/ABAP/UploadXMLfiletointernaltable]

Edited by: Suhas Saha on Jan 19, 2010 7:27 PM

0 Kudos

I told you this is because this # mark only appreas to be so, if you write


data: my_char type string value '#'.
if my_char = value_tab(1).
endif.

and debug the code you would see that it my-char has different hex representation than your val_tab(1) .

It is happening if SAP can't encode this char correctly (as this is one of special character) and presents you with the replacement, which is #. Nevetherless the real value behind it is not what we can see on the screen, it is determined by its hex(binary) representation.

Use my above code replacing


do 31 times.
  xstr = x = sy-index. "convert to hex value and then to xstring
  CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
    EXPORTING
     in_xstring          = xstr
   IMPORTING
     OUT_STRING          = out_str.  "here you have string representation of # with correct hex value behind it

 if out_str = val_tab(1) . "now only compare these two characters
   "....here # was found it means it is one of a special character

 endif.
enddo.

Regards

Marcin

0 Kudos

hi suhas ,

thanks for your reply . you are absolutely right its a garbage .

but when i check my val_tab contains a single '#' and CL_ABAP_CHAR_UTILITIES=>CR_LF contains 2 '##' so the condition is getting false . What to do ?

0 Kudos

thanks a lot the problem is solved .

0 Kudos

Post the solution.