I had to find the algorism for determine the checksum character of a BarCode39 string. It’s easy to do, and I though when I did it to not post the code here because it’s trivial.
But hey, I found the scrap piece of paper where I took my initial notes, and well, I’m in a sharing mood.
I add the ABAP code I wrote. It’s just plain ABAP without any form of art, don’t ask me how it works. If you cannot follow this piece of code, maybe you need to find another field to develop your skills…
FORM checksum USING text1 text2 text3 CHANGING checksum fulltext.
DATA: checktxt(43) TYPE c,
mystring TYPE string,
mylen TYPE i,
mypos TYPE i,
mynumber TYPE i.
checktxt = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'.
CONCATENATE text1 text2 text3 INTO mystring.
mylen = strlen( mystring ).
DO mylen TIMES.
mypos = sy-index - 1.
SEARCH checktxt FOR mystring+mypos(1).
IF sy-subrc 0.
ADD sy-fdpos TO mynumber.
mynumber = mynumber MOD 43.
checksum = checktxt+mynumber(1).
CONCATENATE mystring checksum INTO fulltext.
(some day wordpress’ code tag will preserve indentation… I wish)