代码5S
分类:
2020-05-20 13:21:41
原文地址:MD5的ABAP实现 作者:qdbarry
针对Char类型的的MD5的实现。
REPORT z_barry_test .
DATA: str(1024) TYPE c ,
hash LIKE md5_fields-hash .
str = 'Message digestMessage digestMessage digestMessaget' &
'Message digestMessage digestMessage digestMessaget' &
'Message digestMessage digestMessage digestMessaget' &
'Message digestMessage digestMessage digestMessaget' &
'Message digestMessage digestMessage digestMessaget' .
CALL FUNCTION 'MD5_CALCULATE_HASH_FOR_CHAR'
EXPORTING
data = str
IMPORTING
hash = hash
EXCEPTIONS
internal_error = 1
OTHERS = 2.
WRITE hash.
如果是校验本地文件的MD5值:
DATA: binary_tab TYPE STANDARD TABLE OF x255 ,
bin_len TYPE i ,
hash LIKE md5_fields-hash .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\test.exe'
filetype = 'BIN'
IMPORTING
filelength = bin_len
TABLES
data_tab = binary_tab
EXCEPTIONS
OTHERS = 17.
CALL FUNCTION 'MD5_CALCULATE_HASH_FOR_RAW'
EXPORTING
length = bin_len
IMPORTING
hash = hash
TABLES
data_tab = binary_tab
EXCEPTIONS
internal_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
WRITE hash.