Skip to Content

Introduction:

In this document we will work on printing a Data Matrix barcode (DMC) which is a 2D barcode not supported by SAP.

A 2D (two-dimensional) barcode is a graphical image that stores information both horizontally — as one-dimensional bar codes do — and vertically. As a result of that construction, 2D codes can store up to 7,089 characters and possibly more.

Below are some of the types of 2D barcodes

Capture.PNG

Requirement:

Print Data Matrix barcode (2D barcode) on zebra printers using Smartform.

* Similar approach can be followed for printing other 2D barcodes and the generic barcodes with specific height and width.

Issue:

SAP by default only supports PDF417 as 2D barcode and does not support Data Matrix and other 2D barcodes

Solution:

Printing other 2D barcodes which are not supported by SAP is possible by following the below steps

  • Printer should support the required barcode: We can check this online based on the printer model and make. Most probably you will find this information on the manufacturer’s website.

    

  • Choose an appropriate device type for the printer: Selection of device type is based on the printer you are using.  In this example we are using ZEBRA printer so the device type selction will be based on Zebra printer.This topic is dealt in more detail in the other document named ‘Working with Zebra Printers using Smartforms in SAP’ please refer to the same for additional documentation on selecting the device type for Zebra printers.  For Zebra printers we have the following device types LZEB* (* => 2/3/4) series or YZB# (# => 200/300/400) series based on the DPI resolution of the printer.

        For the demonstration as an example we will use LZEB2 device type from here on in this document.

  • Create a system barcode of type UNDEF in SAP: For creating a system barcode go to transaction SE73.

          This will take you to the SAP script Font Maintenance: Initial screen

        Capture.PNG

          Select System barcodes check box and click the change button. This will display a list of all the Barcodes on the SAP system.

          Click the Create button (Paper icon) at the top of the screen

          Capture.PNG

          The Choose Bar Code Technology select box will now be displayed.

          Capture.PNG

          The barcode we are adding is a new barcode symbology which is not supported by SAP, and the new barcode techcnology allows only specif types

          of barcodes symbologies to be created therefore we are going to use Old technology to create our new barcode as an undefined symbology.

          So Click on Old.

          The Create/Change System Bar Code settings screen will be displayed. For barcode type enter ‘UNDEF’ ( barcode not defined) as the data matrix

          barcode type is not defined in SAP. Also specify the height and width of the barcode.

          Capture.PNG

          Then save the changes by clicking on the Ok button. Now the system barcode ZDMC is created.

  • Create a printer barcode for the newly created system barcode with appropriate print control:

       For creating a system barcode go to transaction SE73. This will take you to the SAP script Font Maintenance: Initial screen

       Capture.PNG

          Select printer barcodes check box and click the change button. This will display a list of device Types available in SAP system.

 

       Capture.PNG

          In this case I am using device type LZEB2 so I will create a printer barcode for this device type. It is advisable to copy this device type to a new

             device type and then make changes to the new Z device type and use it for printing but for demonstration I am using the same device type.

             Double click on the device type to list the barcodes supported by this device type.

              Capture.PNG

               Notice the Prefix and Suffix value ranges used for the barcodes. Here in this case the highest number used for prefix is SBP20 and is different

               for each barcode however the suffix is same for all the barcodes. These prefix and suffix are the print controls of the barcodes supported by

               the printer.

               Now select the create button on the top of the screen to add a new printer barcode. This will take you to the barcode selection screen.

               Capture.PNG

               Select the system barcode you created earlier and enter the other values as shown in the screenshot above. For prefix we are entering SBP21

               because all the numbers from 1 -20 (SBP01 to SBP20) are already used so we are using the next available number SBP21 and the suffix number

               stays the same. We can use any number from 21-99 for prefix.

               Now the barcode is created for the device type (see screen shot  below)

               Capture.PNG

               But the print control SBP21 is empty. For the barcode to work properly we have to add commands in the print control in ZPL-II language

               (printer language).

               Please find the online document named ‘ZPL2 command book‘ . The site link for the same is

               http://www.zebra.com/id/zebra/na/en/documentlibrary/manuals/en/zpl_ii_programming2.File.tmp/45541L-002_RA.pdf

               It is adviced to have the document before we proceed further. This command book has all the commands for printing different types of

               barcodes on a printer ( only if the printer supports it )using the ZPL2 command Lanugage.

               Here we are adding the Data matrix barcode, and the printer command format for printing the data matrix is: ^BXo,h,s,c,r,f,g

               Command Parameters:

               O – Orientation

               H – Height

               S – Quality level

               C – Columns to encode

               R – Rows to encode

               F – Format ID

               G – Escape sequence control character

               Refer to the attached command book for accepted and default values for the above parameters and how to use the command.

           Below is an example of the post script language commands used for printing a DMC barcode on the printer.

           Capture.PNG

            The printer command mainly needs to have 3 types of information

  1.      Command to indicate the type of barcode to be printed ( Marked by ^BX in the command above)
  2.        Command to indicator the start of data ( Marked by ^FD)
  3.        Command to indicator the end of data (Marked by ^FS)

           When working with Smartforms the prefix print control in the printer barcodes screen should have both the commands for the type of barcode

               and the command for the start of data whereas the suffix will only have the command to mark the end of data.

           Capture.PNG

          Taking the above points into consideration we will have ^BXN,2,200,20,20,6,~,1^FD command in prefix and ^FS in suffix.  As the suffix is

             used to mark the end of data it is same for all the barcodes and hence maintained as default.

             Meanings of the command Parameters for prefix ^BXN,2,200,20,20,6,~,1^FD are:

              ^BX        The Data Matrix command

              N            The orientation is normal

              2              Dimensional height in dots of the individual symbol elements

              200         Quality ECC level (ECC 200)

              20           Columns to encode

              20           Rows to encode

              6              Data to be used (6 means full 256 ISO 8-bit data is used)

              ~             Escape sequence for control characters

              1              Square aspect ratio, if you required rectangle this will be 2

              ^FD        This is to mark the start of the field data to be encoded in the barcode

            Add the following command in the print control prefix:  ^BXN,2,200,20,20,6,~,1^FD

            Go to SE73 -> Select printer barcodes -> Change ->Select device type (in this case LZEB2) -> double click to display the list of barcodes supported

            by the device type.

          Capture.PNG

              Select the new print control SBP21 (barcode prefix) and click on Maintain Print control button. Following popup will be displayed.

          Capture.PNG

              Enter the command in the control characters sequence field and make sure the Hexadecimal switch is turned OFF. Then press enter.

              The print control is saved.

               The barcode suffix SBS00, which is default for all the barcodes holds the end of data command (see below)

           Capture.PNG

               The configuration of the printer barcode is complete. Now we can use this barcode to print the Data Matrix barcode (2D barcode) from SAP.

               Note:

               There can be various combinations to the prefix command. If the barcode is not printed then you have to try changing the values for the height,

               rows and columns variables in the command. The prefix combination that worked for me is: ^BXN,3,200,,,6,~,1^FD

               Capture.PNG

  • Use the barcode in the Smartform using a style:

       Please refer to online documentation for adding a barcode to a style in Smartform.

       After you have added the barcodes to one of the character formats of the style which is being used in the Smartform, we just have to use the

         newly created barcode type to display the 2D content as Data Matrix Barcode.

       See below screenshot for an example.

       Capture.PNG

       As the example depicts, use a separate text node for the 2D barcode , keep all the 2D content in a variable or write it all down in the text node.

         Select the whole text and select the character format for the DMC barcode.

        

          At this point if you try to print the barcode it is expected to see the barcode on the printout, but you might not see the barcode printed on the

         printer, the reason as i understood is that based on the ZPL2 command the data should be marked with the start of data command and End of data

         command along with the type of barcode we are trying to print. so the commands should be inserted before and after the text node that holds

          the 2D data content. This will give the printer a command saying that the data between this is to be printed as the barcode symbology specified in

          the command, in our case Data Matrix.

          Note : Preview will not show the barcode because literally this barcode is not in SAP system and will only be printed on the printer. So anything

          concerning the barcode has to be tested on the actual printer not the preview because both the preview and the actual print will be a lot

          different.

  • Create a command node before and after the text node that holds the 2D barcode content:

       See below screen shots for an example on how to create a command node.

   Capture.PNG

        Then enter the prefix print control we created in the printer control input field (see below).

    Capture.PNG

       Create one more command node under the 2d content text node and enter the enter the suffix print control in the printer control input

         field (see below)

    Capture.PNG

        Now test the print on the Zebra printer, the barcode should be printed on the zebra printer as shown in the screen shot below. Now take the

        printout and scan the barcode with any of the android apps or any barcode reader that support DMC barcode. Please note that the printout taken

        on your local printer from a scanned document wont be readable, so it is advised to test the barcode scanning from the actual printout or from the

        Scanned document on your computer.

       Capture.PNG

        After scanning, the barcode should display all the 2D content .

Alignment issues with the 2D barcode:

          After the barcode is printed you might notice alignment issues on the label. To solve the alignment issues the following approach can be used.

          Go to Smartstyle you have used in the Smartform, select the respective paragraph format node you have assigned for the barcode. Here try

          changing the alignment and spacing values (see screen shot below) and try giving it a few trials. You will be able to align barcodes after a few

          combinations.

          Capture.PNG

               Note:

               Please make sure you have enough space for the barcode when designing the layout. I mean if you are planning to have a barcode of size

               1 CM * 1 CM then make use you have a separate window on the layout with space more than the barcode size.

                                                 —————-  THE END  —————–

Please note that the document is based on my personal experience and the online documentation i came across. So if there is any scope of improvements in this document you are most welcome to add your comments.

     

    

To report this post you need to login first.

13 Comments

You must be Logged on to comment or reply to a post.

  1. MF Z

    Thanks for this brilliant article!

    I have a script form which printed A4 size in HP Laser Jet printer,and I want to add data matrix in it,Could you please suggest me some method? Thanks!

    (0) 
    1. umar jawid ahmed syed Post author

      Hi,

           Thanks for the comments, Regarding DMC with Script and HP laser printer is something i have not worked on, but as long as you follow the steps mentioned in this document you will be able to figure it out eventually.

           Only differences would be adding a printcontrol command in the script and the printer language for the HP laser jet printers. So find out the printer language for HP printers, find the appropriate command for DMC (if that is supported by the printer) and create a print control for the device type. and design your script with a seperate window for the 2D barcode and add the print control command in that window.

      use the below link on how to insert print control commmand in scripts.

      http://help.sap.com/saphelp_smehp1/helpdata/en/d1/803286454211d189710000e8322d00/content.htm

      Best of luck. 🙂

      After finishing your development, please do add your comments on any information you would like to share with respect to your development.

      Thanks & Regards,

      Umar.

      (0) 
      1. MF Z

        Thanks Umar,

        I got advice from expert says “the critical point is “for DMC (if that is supported by the printer)”. You would need a Data Matrix barcode (DMC) font loaded or installed in the printer for the printer to support DMC.  I don’t know of any hardware or firmware that is available for HP printers that will add 2D barcodes fonts to the printer.

        So I changed to try postscript and Adobe form.

        (0) 
        1. umar jawid ahmed syed Post author

          Hi Z,

               I happened to check the HP website and figured that HP laser jet does support DMC using their ‘HP Barcode Printing Solution’, but that is something that has to be paid for (or may be its already paid for in your case so just check) and you will get enough support for printing it through SAP if you have the product code of the printer with you by just going to the HELP section of the HP site.

               link for the same is http://www.hp.com/sbso/product/printing/laserjetfonts/barcode.html

          Regards,

          Umar.

          (0) 
          1. MF Z

            Thanks Umar,

            This opens another door for me. I think he means “different sizes 2D barcode is not supported in HP“.I saw Data Matrix and QR in column Scalable Barcode Font marked as “N”. But I’m glad to see 2D barcode is supported in HP.

            (0) 
  2. Gautam Totekar

    Thanks a lot. Thanks for sharing. SInce I am very new to this I have a question.  Will the barcode be reflected on the print preview or it would be reflected on the actual print on ZEBRA.
    After following all the instructions I am getting only Normal bar code on print preview. I checked the ZPL 2 commands and tried various combinations

    eg ^BXN,1,200,48,48,6,~,1^FD

    Any changes in rows and height doesnt have any impact on the barcode in print preview.

    (0) 
    1. umar jawid ahmed syed Post author

      Hi Gautam,

                When working with barcodes that are not supported by the printer device type or SAP, the print preview for the new barcodes won’t be same as the actual print from the printer.

      Reason being, you just created a generic barcode in SAP and the actual barcode type and the length specifications are taken from the print command executed at the printer. so there is always a difference in the print preview and the actual print in such cases. Its already described in the document 🙂 .

      Hope you got your answer…

      Regards,

      Umar.

      (0) 
  3. Simone Milesi

    And 3 years after this blog, thanks again for it!

    i had the same issue printing my QR Code on a Zebra and your blog helped me a lot!

    The only difference, i had to remove the 2 commands in smartforms because they cause some weird behaviour (just for your information 🙂 ).

    But thanks again!

    (0) 

Leave a Reply