Skip to content

Instantly share code, notes, and snippets.

@larshp
Created June 18, 2014 14:35
Show Gist options
  • Save larshp/58409a1e0d58709fcb16 to your computer and use it in GitHub Desktop.
Save larshp/58409a1e0d58709fcb16 to your computer and use it in GitHub Desktop.
Adler32 checksum implemented in ABAP, see http://en.wikipedia.org/wiki/Adler-32
TYPES: t_checksum TYPE x LENGTH 4.
FORM adler32 USING pv_xstring TYPE xstring
CHANGING cv_checksum TYPE t_checksum.
CONSTANTS: c_adler TYPE i VALUE 65521.
DATA: lv_index TYPE i,
lv_a TYPE i VALUE 1,
lv_b TYPE i VALUE 0,
lv_x TYPE x LENGTH 2,
lv_ca TYPE c LENGTH 4,
lv_cb TYPE c LENGTH 4,
lv_char8 TYPE c LENGTH 8.
DO xstrlen( pv_xstring ) TIMES.
lv_index = sy-index - 1.
lv_a = ( lv_a + pv_xstring+lv_index(1) ) MOD c_adler.
lv_b = ( lv_b + lv_a ) MOD c_adler.
ENDDO.
lv_x = lv_a.
lv_ca = lv_x.
lv_x = lv_b.
lv_cb = lv_x.
CONCATENATE lv_cb lv_ca INTO lv_char8.
cv_checksum = lv_char8.
ENDFORM. " ADLER32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment