EAN 13 Code Generator

Has anyone some code to share for generating a EAN13 code based on an Item No which can have a lengh up to 20 chars …

Hi Tarek! I don’t know, if it’s possible to create a EAN13 with a 20-char Number … The EAN13 is created by a 12-digit number and a check-numer (total 13 numbers). Here some Code-Examples, of how we create EAN:

EAN13_Holen() EAN : Code[20]
// EAN13 Nummer generieren
// Prüfziffernberechnung: Gewichtung 1:3, MOD 10
EinrEAN.GET;
EinrEAN.TESTFIELD("ILN Ländercode");     // first 2 digits
EinrEAN.TESTFIELD("ILN Firmennummer");   // next 5 digits (left block)
EinrEAN.TESTFIELD("Letzte EAN-Nummer");  // next 5 digits (right block)

NeueLfdNr := INCSTR(EinrEAN."Letzte EAN-Nummer");
EinrEAN."Letzte EAN-Nummer" := NeueLfdNr;
EinrEAN.MODIFY;

NeueEANNr := STRSUBSTNO('%1%2%3', EinrEAN."ILN Ländercode", EinrEAN."ILN Firmennummer", NeueLfdNr);

Prüfziffer := STRCHECKSUM(NeueEANNr, '131313131313', 10);

EAN := STRSUBSTNO('%1%2%3%4', EinrEAN."ILN Ländercode", EinrEAN."ILN Firmennummer", NeueLfdNr, Prüfziffer);

EXIT(EAN);
EAN13_BarcodeErzeugen(EAN : Text[30]) BarcodeEAN : Text[30]
// EAN13 Barcode erzeugen
// based on TrueTypeFont-Set by ChaosMicrosystems

IF (EAN = '') THEN
  EXIT;

// Ziffernfolge (ohne Blank)
EAN := DELCHR(EAN, '=', ' ');
IF (STRLEN(EAN) <> 13) THEN
  ERROR('EAN %1 ist ungültig.', EAN);

// Sektionen finden
CLEAR(BarcodeEAN);
Flag1 := COPYSTR(EAN, 1, 1);
Flag2 := COPYSTR(EAN, 2, 1);
LinkerTeil := COPYSTR(EAN, 3, 5);
RechterTeil := COPYSTR(EAN, 8, 5);
Check := COPYSTR(EAN, 13, 1);

// Muster festlegen
CASE Flag1 OF
  '0' : Muster := 'AAAAA';
  '1' : Muster := 'ABABB';
  '2' : Muster := 'ABBAB';
  '3' : Muster := 'ABBBA';
  '4' : Muster := 'BAABB';
  '5' : Muster := 'BBAAB';
  '6' : Muster := 'BBBAA';
  '7' : Muster := 'BABAB';
  '8' : Muster := 'BABBA';
  '9' : Muster := 'BBABA';
END;

// Flag 1. Zeichen umsetzen
// Zeichensatz Flag 1. Zeichen
CASE Flag1 OF
  '0' : Char := 33;
  '1' : Char := 34;
  '2' : Char := 35;
  '3' : Char := 36;
  '4' : Char := 37;
  '5' : Char := 38;
  '6' : Char := 39;
  '7' : Char := 40;
  '8' : Char := 41;
  '9' : Char := 42;
END;
Flag1[1] := Char;

// Flag 2. Zeichen umsetzen
// Zeichensatz Flag 2. Zeichen
CASE Flag2 OF
  '0' : Char := 96;
  '1' : Char := 97;
  '2' : Char := 98;
  '3' : Char := 99;
  '4' : Char := 100;
  '5' : Char := 101;
  '6' : Char := 102;
  '7' : Char := 103;
  '8' : Char := 104;
  '9' : Char := 105;
END;
Flag2[1] := Char;

// Linken Teil umsetzen
FOR i := 1 TO STRLEN(LinkerTeil) DO
  IF Muster[i] = 'A' THEN BEGIN

    // Zeichensatz Links A
    CASE LinkerTeil[i] OF
      '0' : Char := 48;
      '1' : Char := 49;
      '2' : Char := 50;
      '3' : Char := 51;
      '4' : Char := 52;
      '5' : Char := 53;
      '6' : Char := 54;
      '7' : Char := 55;
      '8' : Char := 56;
      '9' : Char := 57;
    END;
    LinkerTeil[i] := Char;
  END ELSE BEGIN

    // Zeichensatz Links B
    CASE LinkerTeil[i] OF
      '0' : Char := 64;
      '1' : Char := 65;
      '2' : Char := 66;
      '3' : Char := 67;
      '4' : Char := 68;
      '5' : Char := 69;
      '6' : Char := 70;
      '7' : Char := 71;
      '8' : Char := 72;
      '9' : Char := 73;
    END;
    LinkerTeil[i] := Char;
  END;

// Rechten Teil umsetzen
FOR i := 1 TO STRLEN(RechterTeil) DO BEGIN
  // Zeichensatz Rechts C
  CASE RechterTeil[i] OF
    '0' : Char := 80;
    '1' : Char := 81;
    '2' : Char := 82;
    '3' : Char := 83;
    '4' : Char := 84;
    '5' : Char := 85;
    '6' : Char := 86;
    '7' : Char := 87;
    '8' : Char := 88;
    '9' : Char := 89;
  END;
  RechterTeil[i] := Char;
END;

// Prüfziffer umsetzen
// Zeichensatz Prüfziffer
CASE Check OF
  '0' : Char := 112;
  '1' : Char := 113;
  '2' : Char := 114;
  '3' : Char := 115;
  '4' : Char := 116;
  '5' : Char := 117;
  '6' : Char := 118;
  '7' : Char := 119;
  '8' : Char := 120;
  '9' : Char := 121;
END;
Check[1] := Char;

BarcodeEAN := STRSUBSTNO('%1%2%3|%4%5', Flag1, Flag2, LinkerTeil, RechterTeil, Check);
EXIT(BarcodeEAN);

Maybe this could help you. Best regards, Jörg

And do not forget to use the CORRECT EAN13 font which has the bars at the correct position.

According to the EAN-specifications, each number can have three different representations - depending if they are on the left hand side or at the right hand side and if right - if they are used as even or odd (in this example A or B - depending on the variable FLAG 1.

Additionally :slight_smile: it can be different numbers with the clear text interpretation below or not - so actually three more representations.

So this gives a number of 70 characters (+ 3 for defining Middle seperator lead in and lead out).
These characters are somewhere in the 255 characters of a TTF.