VDA requirement says
The check digit is calculated with the Modulus 43 method:
For this purpose the numeric values of all characters transferred (without control characters) are
added and the sum is divided by 43.
The remaining balance is converted into a character again and transferred in the data record as a
check digit.
Example: the “12345ABCDE” string makes the check digit W. 1+2+3+4+5+10+11+12+13+14 = 75
--> 75 : 43 = 1 Rest 32 -> 32 equals the W character.
I put some simple subroutine into SF to add one DataMatrix code item.
Later on subroutine for modulus 43.
The actual coding looks like this
*&---------------------------------------------------------------------*
*& Form get_check_code
*&---------------------------------------------------------------------*
* get VDA security check character
*----------------------------------------------------------------------*
* -->LV_INPUTDATA_STR text
* -->LV_CHECK_CHAR text
*----------------------------------------------------------------------*
FORM get_check_code
USING
lv_inputdata_str TYPE string
CHANGING
lv_check_char TYPE /fit/lwert.
TYPES: BEGIN OF ty_translation,
input TYPE c1,
value TYPE i,
END OF ty_translation.
DATA: lt_translations TYPE STANDARD TABLE OF ty_translation,
ls_translation LIKE LINE OF lt_translations.
CONSTANTS cv_diviser TYPE i VALUE 43.
ls_translation-input = '0'.
ls_translation-value = 0.
APPEND ls_translation TO lt_translations.
ls_translation-input = '1'.
ls_translation-value = 1.
APPEND ls_translation TO lt_translations.
ls_translation-input = '2'.
ls_translation-value = 2.
APPEND ls_translation TO lt_translations.
ls_translation-input = '3'.
ls_translation-value = 3.
APPEND ls_translation TO lt_translations.
ls_translation-input = '4'.
ls_translation-value = 4.
APPEND ls_translation TO lt_translations.
ls_translation-input = '5'.
ls_translation-value = 5.
APPEND ls_translation TO lt_translations.
ls_translation-input = '6'.
ls_translation-value = 6.
APPEND ls_translation TO lt_translations.
ls_translation-input = '7'.
ls_translation-value = 7.
APPEND ls_translation TO lt_translations.
ls_translation-input = '8'.
ls_translation-value = 8.
APPEND ls_translation TO lt_translations.
ls_translation-input = '9'.
ls_translation-value = 9.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'A'.
ls_translation-value = 10.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'B'.
ls_translation-value = 11.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'C'.
ls_translation-value = 12.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'D'.
ls_translation-value = 13.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'E'.
ls_translation-value = 14.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'F'.
ls_translation-value = 15.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'G'.
ls_translation-value = 16.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'H'.
ls_translation-value = 17.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'I'.
ls_translation-value = 18.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'J'.
ls_translation-value = 19.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'K'.
ls_translation-value = 20.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'L'.
ls_translation-value = 21.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'M'.
ls_translation-value = 22.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'N'.
ls_translation-value = 23.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'O'.
ls_translation-value = 24.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'P'.
ls_translation-value = 25.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'Q'.
ls_translation-value = 26.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'R'.
ls_translation-value = 27.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'S'.
ls_translation-value = 28.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'T'.
ls_translation-value = 29.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'U'.
ls_translation-value = 30.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'V'.
ls_translation-value = 31.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'W'.
ls_translation-value = 32.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'X'.
ls_translation-value = 33.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'Y'.
ls_translation-value = 34.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'Z'.
ls_translation-value = 35.
APPEND ls_translation TO lt_translations.
ls_translation-input = '-'.
ls_translation-value = 36.
APPEND ls_translation TO lt_translations.
ls_translation-input = '.'.
ls_translation-value = 37.
APPEND ls_translation TO lt_translations.
ls_translation-input = ' '.
ls_translation-value = 38.
APPEND ls_translation TO lt_translations.
ls_translation-input = '$'.
ls_translation-value = 39.
APPEND ls_translation TO lt_translations.
ls_translation-input = '/'.
ls_translation-value = 40.
APPEND ls_translation TO lt_translations.
ls_translation-input = '+'.
ls_translation-value = 41.
APPEND ls_translation TO lt_translations.
ls_translation-input = '%'.
ls_translation-value = 42.
APPEND ls_translation TO lt_translations.
*
TRANSLATE lv_inputdata_str TO UPPER CASE.
DATA: lv_char TYPE c,
lv_offset TYPE syindex,
lv_sum TYPE i,
lv_rest TYPE i.
" get sum of character values
DO strlen( lv_inputdata_str ) TIMES.
lv_offset = sy-index - 1.
lv_char = lv_inputdata_str+lv_offset.
IF lv_char IS NOT INITIAL.
CLEAR ls_translation.
READ TABLE lt_translations WITH KEY input = lv_char INTO ls_translation.
IF sy-subrc EQ 0.
lv_sum = lv_sum + ls_translation-value.
ENDIF.
ENDIF.
ENDDO.
" get proper 43 return code
IF lv_sum NE 0.
lv_rest = lv_sum MOD cv_diviser.
CLEAR ls_translation.
READ TABLE lt_translations WITH KEY value = lv_rest INTO ls_translation.
IF sy-subrc EQ 0.
lv_check_char = ls_translation-input.
ENDIF.
ENDIF.
ENDFORM. "get_check_code
*& Form get_check_code
*&---------------------------------------------------------------------*
* get VDA security check character
*----------------------------------------------------------------------*
* -->LV_INPUTDATA_STR text
* -->LV_CHECK_CHAR text
*----------------------------------------------------------------------*
FORM get_check_code
USING
lv_inputdata_str TYPE string
CHANGING
lv_check_char TYPE /fit/lwert.
TYPES: BEGIN OF ty_translation,
input TYPE c1,
value TYPE i,
END OF ty_translation.
DATA: lt_translations TYPE STANDARD TABLE OF ty_translation,
ls_translation LIKE LINE OF lt_translations.
CONSTANTS cv_diviser TYPE i VALUE 43.
ls_translation-input = '0'.
ls_translation-value = 0.
APPEND ls_translation TO lt_translations.
ls_translation-input = '1'.
ls_translation-value = 1.
APPEND ls_translation TO lt_translations.
ls_translation-input = '2'.
ls_translation-value = 2.
APPEND ls_translation TO lt_translations.
ls_translation-input = '3'.
ls_translation-value = 3.
APPEND ls_translation TO lt_translations.
ls_translation-input = '4'.
ls_translation-value = 4.
APPEND ls_translation TO lt_translations.
ls_translation-input = '5'.
ls_translation-value = 5.
APPEND ls_translation TO lt_translations.
ls_translation-input = '6'.
ls_translation-value = 6.
APPEND ls_translation TO lt_translations.
ls_translation-input = '7'.
ls_translation-value = 7.
APPEND ls_translation TO lt_translations.
ls_translation-input = '8'.
ls_translation-value = 8.
APPEND ls_translation TO lt_translations.
ls_translation-input = '9'.
ls_translation-value = 9.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'A'.
ls_translation-value = 10.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'B'.
ls_translation-value = 11.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'C'.
ls_translation-value = 12.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'D'.
ls_translation-value = 13.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'E'.
ls_translation-value = 14.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'F'.
ls_translation-value = 15.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'G'.
ls_translation-value = 16.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'H'.
ls_translation-value = 17.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'I'.
ls_translation-value = 18.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'J'.
ls_translation-value = 19.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'K'.
ls_translation-value = 20.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'L'.
ls_translation-value = 21.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'M'.
ls_translation-value = 22.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'N'.
ls_translation-value = 23.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'O'.
ls_translation-value = 24.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'P'.
ls_translation-value = 25.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'Q'.
ls_translation-value = 26.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'R'.
ls_translation-value = 27.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'S'.
ls_translation-value = 28.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'T'.
ls_translation-value = 29.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'U'.
ls_translation-value = 30.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'V'.
ls_translation-value = 31.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'W'.
ls_translation-value = 32.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'X'.
ls_translation-value = 33.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'Y'.
ls_translation-value = 34.
APPEND ls_translation TO lt_translations.
ls_translation-input = 'Z'.
ls_translation-value = 35.
APPEND ls_translation TO lt_translations.
ls_translation-input = '-'.
ls_translation-value = 36.
APPEND ls_translation TO lt_translations.
ls_translation-input = '.'.
ls_translation-value = 37.
APPEND ls_translation TO lt_translations.
ls_translation-input = ' '.
ls_translation-value = 38.
APPEND ls_translation TO lt_translations.
ls_translation-input = '$'.
ls_translation-value = 39.
APPEND ls_translation TO lt_translations.
ls_translation-input = '/'.
ls_translation-value = 40.
APPEND ls_translation TO lt_translations.
ls_translation-input = '+'.
ls_translation-value = 41.
APPEND ls_translation TO lt_translations.
ls_translation-input = '%'.
ls_translation-value = 42.
APPEND ls_translation TO lt_translations.
*
TRANSLATE lv_inputdata_str TO UPPER CASE.
DATA: lv_char TYPE c,
lv_offset TYPE syindex,
lv_sum TYPE i,
lv_rest TYPE i.
" get sum of character values
DO strlen( lv_inputdata_str ) TIMES.
lv_offset = sy-index - 1.
lv_char = lv_inputdata_str+lv_offset.
IF lv_char IS NOT INITIAL.
CLEAR ls_translation.
READ TABLE lt_translations WITH KEY input = lv_char INTO ls_translation.
IF sy-subrc EQ 0.
lv_sum = lv_sum + ls_translation-value.
ENDIF.
ENDIF.
ENDDO.
" get proper 43 return code
IF lv_sum NE 0.
lv_rest = lv_sum MOD cv_diviser.
CLEAR ls_translation.
READ TABLE lt_translations WITH KEY value = lv_rest INTO ls_translation.
IF sy-subrc EQ 0.
lv_check_char = ls_translation-input.
ENDIF.
ENDIF.
ENDFORM. "get_check_code
No comments:
Post a Comment