METHODS:
get_hash_value_for_itab
IMPORTING
it_table TYPE ANY TABLE
EXPORTING
ev_hash TYPE hash160.
METHOD get_hash_value_for_itab.
DATA: lv_string TYPE xstring,
lv_xbuffer TYPE xstring.
" Clear the hash value
CLEAR ev_hash.
" Go through the table one line at a time
LOOP AT it_table ASSIGNING FIELD-SYMBOL(<ls_line>).
DATA(lv_index) = 0.
CLEAR lv_string.
" Concatenate all the columns of the line into one string
DO.
ASSIGN COMPONENT lv_index OF STRUCTURE <ls_line> TO FIELD-SYMBOL(<lv_field>) CASTING TYPE x.
IF sy-subrc EQ 0.
CONCATENATE lv_string <lv_field> INTO lv_string IN BYTE MODE.
ADD 1 TO lv_index.
ELSE.
EXIT.
ENDIF.
ENDDO.
" Add the string from the line to our buffer
CONCATENATE lv_xbuffer lv_string INTO lv_xbuffer IN BYTE MODE.
ENDLOOP.
" Calculate the hash value for the entire buffer/table
CALL FUNCTION 'CALCULATE_HASH_FOR_RAW'
EXPORTING
data = lv_xbuffer
IMPORTING
hash = ev_hash
EXCEPTIONS
unknown_alg = 1
param_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
" Do error handling here
ENDIF.
ENDMETHOD.
DATA:
lv_hash_old TYPE hash160,
lv_hash_new TYPE hash160.
me->get_hash_value_for_itab(
EXPORTING
it_table = gt_final_req
IMPORTING
ev_hash = lv_hash_old ).
IF lv_hash_old <> lv_hash_new.
“ There's a difference
ENDIF.
cl_aunit_assert=>assert_equals(
act = lv_hash
exp = '5CAF285B3FA1C3F971BBEEEE1D61EF9095B6F4CC'
msg = 'Hash value for output not correct'
).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |