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: 

Comparing Hexadecimal value in program

Former Member
0 Kudos

Hi friends,

I have requirement in this I have to pick a file and have to write some logic by comparing file contents.

File contents some hexadecimal character like '#'.

When I am writing simple if condition like

if var = '#'.

---

endif.

It is not going in that if condition even when the var has value from # from file. so i think as it is hexadecimal value there is some other way to compare it.

Please let me know how can I compare hexadecimal value.

1 ACCEPTED SOLUTION

MarcinPciak
Active Contributor
0 Kudos

Indeed # is a character representation of a separator (tab or space) which is seen as # in character mode.

Use below snippet to compare it


DATA: xsep TYPE xstring,
                sep TYPE string.

              xsep = '09'. "if separator is tab mark
              xsep = '20'. "if it is space

          CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
            EXPORTING
              in_xstring = xsep
            IMPORTING
              out_string = sep.

         "now SEP contains character representation for separator (which is seen as #)
          "you can i.e. split uploaded file data (in iternal table) based on that separator
          SPLIT it_file_data AT sep INTO TABLE it_file_fields IN CHARACTER MODE.

          "for comparing use
          if var = sep.
              ...
          endif.

Regards

Marcin

4 REPLIES 4

MarcinPciak
Active Contributor
0 Kudos

Indeed # is a character representation of a separator (tab or space) which is seen as # in character mode.

Use below snippet to compare it


DATA: xsep TYPE xstring,
                sep TYPE string.

              xsep = '09'. "if separator is tab mark
              xsep = '20'. "if it is space

          CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
            EXPORTING
              in_xstring = xsep
            IMPORTING
              out_string = sep.

         "now SEP contains character representation for separator (which is seen as #)
          "you can i.e. split uploaded file data (in iternal table) based on that separator
          SPLIT it_file_data AT sep INTO TABLE it_file_fields IN CHARACTER MODE.

          "for comparing use
          if var = sep.
              ...
          endif.

Regards

Marcin

0 Kudos

Hi Marcin

I tried the method u showed but its not working, I think that # symbol there represent line feed or carriage return and not space.

What is the value of line feed and carriage return, as 20 for space?

0 Kudos

Hex:

Carriage return - '0D'

Newline (so called line feed) - 'A'

Char:

Carriage return and line feed - use CL_ABAP_CHAR_UTILITIES=>CR_LF

Only newline - CL_ABAP_CHAR_UTILITIES=>NEWLINE

Regards

Marcin

0 Kudos

Hi Marcin,

I was able to get the proper split value using hex decimal '0A'.

I got it from this link http://www.dynamoo.com/technical/ascii.htm

Thanks for your help...