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: 

'#' symbol in if condition

Former Member
0 Kudos
345

Hi All,

I want to use '#' in if condition.

i have written the code like this.But it doesn't work for me.

data : test(1) type c value '#'.

CONSTANTS: k_tab TYPE abap_char1 VALUE cl_abap_char_utilities=>HORIZONTAL_TAB.

*CONSTANTS: k_tab TYPE abap_char1 VALUE cl_abap_char_utilities=>HORIZONTAL_TAB.

*write : k_tab.

if test = k_tab.

write : k_tab.

endif.

Can you please teel how to use the # in condition.

Thanks,

Swapna.

8 REPLIES 8

matt
Active Contributor
0 Kudos
130

It's quite simple: # is not equal to cl_abap_char_utilities=>HORIZONTAL_TAB

Run in debug and check the hex values: test is x23, k_tab is x09. It's just that in character view, they look the same in the debugger, in list views etc.

Former Member
0 Kudos
130

Yes i got that but how to compare the hex values in the program

Former Member
0 Kudos
130

we can convert using convert command

Former Member
0 Kudos
130

can you please teel me what is the correct solution for my problem.

matt
Active Contributor
0 Kudos
130

>

> Yes i got that but how to compare the hex values in the program

What do you mean? Are you expecting to run your program and have k_tab written out? You compare using = or EQ exactly as you've written it. The hex values of test and k_tab are not the same, so code between IF and ENDIF doesn't trigger.

DATA : test(1) TYPE c VALUE ' ',
      test2(1) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
CONSTANTS: k_tab TYPE abap_char1 VALUE cl_abap_char_utilities=>horizontal_tab.

IF test = k_tab.
  WRITE / 'test and k_tab are the same'. 
ELSE.
  WRITE / 'test and k_tab are not the same'.  " This bit is run when you run the program
ENDIF.

IF test2 = k_tab.
  WRITE / 'test2 and k_tab are the same'.  " This bit is run when you run the program
ELSE.
  WRITE / 'test2 and k_tab are not the same'.
ENDIF.

output

test and k_tab are not the same  
test2 and k_tab are the same     

matt

Former Member
0 Kudos
130

hi swapna,

i faced the same problem few days back...in sap it convert some symbols into #,we will see it as # but internally it will be different symbol,the solution for this is copy the symbol from orginal file and paste in abap editor

Former Member
0 Kudos
130

Hi Swapna,

As Matt said both are different . Check the code to see how it behaves.

If you want to check tab values use cl_abap_char_utilities=>horizontal_tab in IF statement

DATA : itab TYPE TABLE OF string,
       wa   TYPE string,
       val1 TYPE string,
       val2 TYPE string.

CONCATENATE 'ABC' cl_abap_char_utilities=>horizontal_tab 'DEF' INTO wa.
APPEND wa TO itab.

CONCATENATE 'ABC' cl_abap_char_utilities=>horizontal_tab 'DEF' INTO wa.
APPEND wa TO itab.

CONCATENATE 'ABC' cl_abap_char_utilities=>horizontal_tab 'DEF' INTO wa.
APPEND wa TO itab.

LOOP AT itab INTO wa.

  SPLIT wa AT cl_abap_char_utilities=>horizontal_tab INTO val1 val2.

  WRITE : / val1, val2.

ENDLOOP.

REFRESH ITAB.

CONCATENATE 'ABC' '#' 'DEF' INTO wa.
APPEND wa TO itab.

CONCATENATE 'ABC' '#' 'DEF' INTO wa.
APPEND wa TO itab.

CONCATENATE 'ABC' '#' 'DEF' INTO wa.
APPEND wa TO itab.


LOOP AT itab INTO wa.

  SPLIT wa AT '#' INTO val1 val2.

  IF wa CS '#'.

    WRITE : / ' File contains #'.

  ENDIF.

  WRITE : / val1, val2.

ENDLOOP.

Regards

Former Member
0 Kudos
130

REPORT ZSRK_070 .

CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.

CONSTANTS: K_TAB TYPE ABAP_CHAR1 VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

DATA : TEST(1) TYPE C.

DATA: HTAB TYPE X VALUE '09'.

FIELD-SYMBOLS : <FS_TR> TYPE X,

<FS_TR1> TYPE C.

ASSIGN HTAB TO <FS_TR>.

ASSIGN <FS_TR> TO <FS_TR1> CASTING.

TEST = <FS_TR1>.

IF TEST = K_TAB.

WRITE : K_TAB.

ENDIF.

If u want to know the hex value of k_tab check the below code u can notice the hex value is '09'

REPORT ZSRK_070 .

CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.

CONSTANTS: K_TAB TYPE ABAP_CHAR1 VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

DATA : TEST(1) TYPE C.

DATA: HTAB TYPE X VALUE '09'.

FIELD-SYMBOLS : <FS_TR> TYPE X,

<FS_TR1> TYPE C.

ASSIGN K_TAB TO <FS_TR1>.

ASSIGN <FS_TR1> TO <FS_TR> CASTING TYPE X.

WRITE : / <FS_TR>.