2008 Nov 19 11:48 AM
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.
2008 Nov 19 11:49 AM
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.
2008 Nov 19 11:52 AM
Yes i got that but how to compare the hex values in the program
2008 Nov 19 11:54 AM
2008 Nov 19 11:58 AM
can you please teel me what is the correct solution for my problem.
2008 Nov 19 12:42 PM
>
> 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
2008 Nov 19 11:53 AM
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
2008 Nov 19 12:02 PM
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
2008 Nov 19 12:10 PM
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>.