Skip to Content

Using function module MD5_CALCULATE_HASH_FOR_CHAR for cyrillic characters

Hey SAPlers!

I recently tried to use the function module 'MD5_CALCULATE_HASH_FOR_CHAR' for cyrillic characters, but unfortunately noticed that different strings produce the same hash. Is this because the codepage is different? If so, how can I still use cyrillic characters?

See the sample code below.

REPORT Z_TEST_HASH.


DATA: string1 TYPE string VALUE 'CUS&ДЕКЛT9',
      string2 TYPE string VALUE 'CUS&КОРРT9',
      hash1(32) TYPE c,
      hash2(32) TYPE c.


CALL FUNCTION 'MD5_CALCULATE_HASH_FOR_CHAR'
    EXPORTING
      data           = string1
    IMPORTING
      hash           = hash1
    EXCEPTIONS
      no_data        = 1
      internal_error = 2
      OTHERS         = 3.

CALL FUNCTION 'MD5_CALCULATE_HASH_FOR_CHAR'
    EXPORTING
      data           = string2
    IMPORTING
      hash           = hash2
    EXCEPTIONS
      no_data        = 1
      internal_error = 2
      OTHERS         = 3.

BREAK-POINT.
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Aug 28 at 01:05 PM

    Hi Fredrik,
    Have you tried class CL_ABAP_MESSAGE_DIGEST?

    FM MD5_CALCULATE_HASH_FOR_CHAR has status "Not Released", so it should not be used (SAP Note 109533).

    Regards,

    Cris

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 29 at 07:17 AM

    Hi Fredrik,

    MD5_CALCULATE_HASH_FOR_CHAR is a wrapper around CALCULATE_HASH_FOR_RAW and in it a character conversion to hardcoded code page 1100 i.e. (ISO code page 8859-1, Western European languages) is done, where all cyrillic characters are converted to #.

    Use CALCULATE_HASH_FOR_CHAR and specify the algorithm.

    The following should work.

    REPORT Z_TEST_HASH.
    
    DATA: string1 TYPE string VALUE 'CUS&ДЕКЛT9',
          string2 TYPE string VALUE 'CUS&КОРРT9',
          hash1   TYPE HASH160,
          hash2   TYPE HASH160.
    
      CALL FUNCTION 'CALCULATE_HASH_FOR_CHAR'
        EXPORTING
          ALG                  = 'MD5'
          DATA                 = string1
        IMPORTING
          HASH                 = hash1
        EXCEPTIONS
          UNKNOWN_ALG          = 1
          PARAM_ERROR          = 2
          INTERNAL_ERROR       = 3
          OTHERS               = 4.
    
      CALL FUNCTION 'CALCULATE_HASH_FOR_CHAR'
        EXPORTING
          ALG                  = 'MD5'
          DATA                 = string2
        IMPORTING
          HASH                 = hash2
        EXCEPTIONS
          UNKNOWN_ALG          = 1
          PARAM_ERROR          = 2
          INTERNAL_ERROR       = 3
          OTHERS               = 4.
    
    BREAK-POINT.

    Regards

    Robert

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.