Skip to content

Instantly share code, notes, and snippets.

@cbuckowitz
Created December 8, 2017 18:08
Show Gist options
  • Save cbuckowitz/959cd55e02d9b40f22dfee70f0fa71fc to your computer and use it in GitHub Desktop.
Save cbuckowitz/959cd55e02d9b40f22dfee70f0fa71fc to your computer and use it in GitHub Desktop.
Create hash from single value #SAP #ABAP

The standard class CL_ABAP_MESSAGE_DIGEST can generate hashes for string or raw data.

This sample builds a hash from a single input character value.

DATA lo_digest TYPE Ref To cl_abap_message_digest.
DATA lv_timestamp TYPE timestampl.
DATA lv_hash_string TYPE string.
DATA lv_hash_base64 TYPE string.
* prepare test data
GET TIME STAMP FIELD lv_timestamp.
cl_abap_message_digest=>calculate_hash_for_char(
EXPORTING
if_algorithm = 'sha1'
if_data = |{ lv_timestamp }|
IMPORTING
ef_hashstring = lv_hash_string
ef_hashb64string = lv_hash_base64
).
* output hashes
WRITE: / 'Hash string: ', lv_hash_string.
WRITE: / 'Base64 string: ', lv_hash_base64.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment