Barcode Labels

Embed Size (px)

DESCRIPTION

barcode

Citation preview

  • 2010 SAP Professional JournalReproductionprohibited.Allrightsreserved.

    Many companies use barcode printing to improve their day-to-day business opera-tions through better data management and accessibility. It helps companies to reduce costs, increase productivity, and eliminate human error. We explain how to write a custom ABAP report in SAP ERP to design and format labels. In con-trast to using third-party software for this formatting, the ABAP program gives you greater control and flexibility of the output. You can use different sets of commands to print text and barcodes on the labels to suit your needs.

    PrerequisitesYou first should define the SATO printer as one of the output devices by using transaction SPAD. Click the Output devices button and then click the Access Method tab (Figure 1).

    Next, click the Output Attributes tab. Then set the Host spool cover page, Print mode, and Paper tray fields to the values displayed in Figure 2. The rest of the fields should be set up as blank default values. By doing this, you are providing output request processing parameters for the list drivers and SAP Smart Forms.

    Then click the Tray Info tab and leave the values blank. These values are blank by default. You do not need to delete information on this screen.

    Click the Device Attributes tab and then click Device Type (Figure 3). In the screen that appears, enter the values in Figure 4 under the Attributes tab to provide information about SAPscript handling, list handling, and the printer character set.

    Next, click the Print Controls tab to define the custom escapes sequence. Defining these custom escapes sequences increases the readability of label form programs because they are common command strings for the printer. The custom escape sequence in Figure 5 on page 6 should be main-tained along with hexadecimal values. Some escape sequences may be found in the programming manual of the printer. You add or remove them depending on how frequently they are used in label programming. These text command strings need to be coded in

    ASCII code. They also include binary code, such as escape characters (e.g., ESC, 0x1b). Its best to define them in hexadecimal values so that you can make sure the command is sent to the printer in the way you want.

    Standard SAP table T022D should have the entries listed in Figure 6 (on page 7) after you set up the custom print

    UncoverastrategythatenablesyoutoprintbarcodelabelsfromSAPERPusingSATOprint-ers.FindouthowyoucancreateaSATOBarcodeProgramlanguagedatastreamfromanABAPreportthatcontainsthecommandforprintingtext,boxes,andbarcodes.

    Design and Format Barcode Labels Easily with a Custom ABAP Program

    by Tomoyuki Niijima, Senior IT Architect, IBM Japan, and Vipin Nagpal, Senior Advisory Consultant, IBM India Pvt. Ltd.

    Labelsarecommonlyusedinwarehousemanagementandretailoperations.SATOprintersusethermalprintingtechnologytoprintlabelimagesonsmallstickerlabelpaperarrayedonrollpaper.Thelabelscontaininformationsuchasbarcode,quantity,price,andotherimportanttext,includ-ingmaterialname.UsingtheSATO Barcode Program language (SBPL)inSAPERPenablesyoutodefinethelabelformatandthelabelprintingprocess.

    Key Concept>>

    Providetheaccessmethod,printer,anddestinationhostFigure 1

  • Volume 12, Update 5 www.SAPpro.com

    Forgroupratesonelectronicaccess,call1-781-751-8799

    SettheHostspoolcoverpage,Printmode,andPapertraydefaultvaluesFigure 2

    ClicktheDeviceTypelinkFigure 3

    control successfully. The table enables you to confirm the name of each print control and define their values.

    For example, we defined a command string 1B48 as a series of hexadecimal values for the custom print control ZESCH. This means you have two bytes, 0x1B and 0x48, in the command. 0x1B representing escape character (ESC) and 0x48 is for ASCII character H. The SBPL Programming Guide describes the command as H, which is equal to the above two bytes of sequence. We name it ZESCH by defin-ing the print control so that we can use the name through label form program-ming instead of using hexadecimal values in the source code. Use of these controls depends on which functionality of the printer you use to print the label design you want.

    SettheattributevaluesFigure

    >>Tip!AllthebasicSBPLcommandsareintheSBPLProgrammingGuide.Refertowww.asciitable.comtofindtheequivalenthexadecimalvaluesforeachcharacterusedinSBPLcommands.

    >>NoteAnalternativemethodtothisprocessistoprintbarcodesusingSAPSmartForms.However,thismethoddoesnotletyouusecustomprintcontrols.Instead,youneedtoprovidethefullSBPLcommandinstandardtext,whichmakesitdifficulttomaintainstandardtextvalues.

  • 2010 SAP Professional JournalReproductionprohibited.Allrightsreserved.

    AnalysisProgramming the label form using SBPL commands is not just ABAP pro-gramming but programming using commands for the printer. You need to understand the proper sequence and use of each SBPL commands to make the appropriate series of commands.

    You specify paper size, adjust the zero point of the X-Y coordinate, align the location of each graphical object, specify font types and sizes, draw lines and boxes, and eject and cut labels using many different SBPL commands in the right order with the right parameters.

    These command sequences are also called the printer data stream. You use ABAP programming language to gener-ate the printer data stream, which is a proper program for the label printer.

    The printer data stream must begin with the start command A and end with the command Z, where

    means the ESC control charac-ter 1B in hexadecimal expression. The first command after the start command should be the media size command A1, which defines the height and width of the label paper you use. These parameters must be specified in a number of dots. You need to understand the resolution of your label printer to understand how many dots are equal to the length you want to specify.

    Each model of SATO label printer has its own resolution (dots per millimeter [mm]). It can be 12 dots per mm, 8 dots per mm, or something else, depending on the design of each printer model. Twelve dots per mm model is assumed in this article. Therefore, if you use 25mm height by 50mm width of paper, you specify 300 dots of height and 600 dots of width for the A1 command as in the following example:

    A103000600

    The 0300 after A1 means paper height

    >>NoteWewalkthrougheachpartofthecustomABAPcodeinthissection.Toviewtheentirecode,downloadthecodefileavailableatthebottomofthisarticleonline.

    ListofdefinedprintcontrolsFigure

  • Volume 12, Update 5 www.SAPpro.com

    Forgroupratesonelectronicaccess,call1-781-751-8799

    command V, and the M font command M.

    H0000

    V0030

    MHello World!

    In this code, the 0000 in the horizontal print position command H moves the printing position 0 dots from the base reference point specified by the start point command A3. The vertical print position command V moves the printing position in 30 dots. The M font command M prints text after the command from the position specified by the print position command, 0 dots right and 30 dots down (Figure 6). That location I specified is just an example. You can specify any value to locate the text wherever you want.

    You can use the FW command to draw a box on the label. You must position the box by using the H and V com-mands before drawing the box with the FW command, just as you do for the M font command. The FW command is used to draw the box and the M com-mand is used to print the text. The H and V commands specify the top-left corner of the box. The FW command requires four parameters to draw the box: horizontal line width, vertical line width, box width, and box height. Here is a part of the data stream of the form that prints the box:

    H0000

    V0016

    FW0404H0568V0230

    The H and V commands work exactly the same as the M font command. The first two digits (04) follow FW, which means horizontal line width. The second two digits (04) represent the vertical line width. H0568 refers to the box width and V0230 after that means box height. Figure 7 contains the ABAP code that

    Hello World!

    Default base reference point after reboot

    Base reference point moved by A3 command

    Maximum paper width

    Paper movement direction

    Base reference point moved by A1 command

    Located by H0000 and V0024

    M font text

    Height = 300 dots

    Label paper

    Base paper

    Width = 600 dots

    TheoutputHelloWorldonlabelpaperasdesignatedbythebasereferencepoint

    Figure

    and 0600 at the end of the command means paper width. The A1 command moves the base reference point based on how you describe the X-Y location of each graphical object to the top-left corner of the specified paper.

    The start point correction command A3 follows the media size command to move the base reference point relatively from the top-left corner of the paper. The following example moves the base reference point 0024 dots horizontally and 0048 dots verti-cally (24 dots is 2 mm and 48 dots is 4 mm in the resolution).

    A3H0024V0048

    Label papers are designed as sticker

    labels and aligned on removable base paper. Base paper is slightly wider than label paper in a long roll with many sticker label papers on it. The paper size we specified with the A1 command was the size of one unit area of base paper, which encloses one sticker label paper. Because label paper is smaller than base paper, the printable area is a little inside of the paper from the top-left corner. Then you need to adjust the base refer-ence point again with the A3 command to move it a little inside of the paper.

    The three lines in the following example are a set of commands to print Hello World! These lines include the horizontal print position command H, the vertical print position

    PRINT-CONTROL FUNCTION 'ZESCH'.

    WRITE '0000' NO-GAP.

    PRINT-CONTROL FUNCTION 'ZESCV'.

    WRITE '0016' NO-GAP.

    PRINT-CONTROL FUNCTION 'ESCAP'.

    WRITE 'FW0404H0568V0230' NO-GAP.

    FWcommandwithheightandwidthdimensionsFigure

  • 2010 SAP Professional JournalReproductionprohibited.Allrightsreserved.

    generates this data stream. This piece of the code can be part of the report program that you write to draw the label.

    Draw the LineFigure 8 shows a label with a line, which is part of the label output. You draw the line by using a similar sequence as that for a box.

    Here is the data stream for the line:

    H0000

    V0064

    FW02H0568

    In this data stream, 02 follows FW, which means line width. The H0568 after that refers to the line length. Specify V instead of H if you intend to draw a vertical line. Use of a vertical line depends on end-user requirements to have a vertical line on the label output. Figure 9 contains the ABAP code for the horizontal line. This piece of the code can be part of the report program.

    FontsSATO Printer model SR412 supports various type and size of fonts. A typical one is raster fonts as M fonts (Figure 10). A raster font (also known as a bitmap font) is a font in which each characters glyph is defined by a bitmap. A glyph is the actual shape of a character image. The data steam prints the two circled raster font texts.

    Other than raster fonts, the printer sup-ports TrueType fonts, which you can draw by using a series of $ commands. Figure 11 shows the part of the data stream that prints TrueType font text for the TRACE-

    Line by FW command

    Positioned by H and V command

    AhorizontallinecanbedrawnonthelabelwiththeFWcommandFigure

    PRINT-CONTROL FUNCTION 'ZESCH'.

    WRITE '0000' NO-GAP.

    PRINT-CONTROL FUNCTION 'ZESCV'.

    WRITE '0064' NO-GAP.

    PRINT-CONTROL FUNCTION 'ESCAP'.

    WRITE 'FW02H0568' NO-GAP.

    TheFWcommandwithheightdimensionFigure 9

    True type font

    Line by FW command

    M font

    Positioned by H and V command

    LabeloutputwiththeeffectoftheMcommandFigure 10

    H0112

    V0016

    $A,50,50,8

    $=TRACEABLE LABEL

    SPBL$commandtoprinttextwithitalicfontFigure 11

    Theprinteralsosupportsthe$Bcommandthatfixesthespacingforthetext.

    Note>>

  • Volume 12, Update 5 www.SAPpro.com

    Forgroupratesonelectronicaccess,call1-781-751-8799 9

    PRINT-CONTROL FUNCTION 'ZESCH'.

    WRITE '0112' NO-GAP.

    PRINT-CONTROL FUNCTION 'ZESCV'.

    WRITE '0016' NO-GAP.

    PRINT-CONTROL FUNCTION 'ESCAP'.

    WRITE '$A,50,50,8' NO-GAP.

    PRINT-CONTROL FUNCTION 'ESCAP'.

    WRITE '$=TRACEABLE LABEL' NO-GAP.

    ABAPprintcontrolcommandtoprintitalictextwith$commandFigure 12

    PRINT-CONTROL FUNCTION 'ZESCH'.

    WRITE '0048' NO-GAP.

    PRINT-CONTROL FUNCTION 'ZESCV'.

    WRITE '0070' NO-GAP.

    PRINT-CONTROL FUNCTION 'ESCAP'.

    WRITE 'BG03060' NO-GAP.

    WRITE '1234567890' NO-GAP.

    ABAPcodeexampletoprintbarcodeonlabelprinterFigure 13

    label output. These values are explained in the description of Figure 11. The full ABAP code for TRACEABLE LABEL is at the bottom of this article.

    SR412 also supports various types of barcode fonts. TRACEABLE LABEL uses CODE128 as shown in the barcode in Figure 10. CODE128 is one of the industry standard barcode architectures with which you can print all ASCII characters. Code 128 is a high-density alphanumeric barcode designed to encode all 128 ASCII characters. The following is the part of the data stream that prints the barcode:

    H0048

    V0070

    BG030601234567890

    The H and V commands work as in the other examples. B followed by G means printing barcode in CODE128. 03 after G represents the width of the narrow bar in dots and 060 refers to the height of the bar in dots. The remaining text, 1234567890, is printed in the barcode. Figure 13 shows the ABAP code for this process. n

    Tomoyuki Niijima is a certified IT architect at IBM. He has been working mainly in high performance and high availability computing areas for the last 20 years. He is also interested in, and actively working in, technical areas such as operating systems, programming languages, communication and application protocols, peripheral devices, and open source software. You may contact him via email at [email protected].

    Vipin Nagpal is an SAP ERP technical consultant specializing in ABAP. He has a masters degree in engineering from BITS Pilani University, specializing in software systems. He has more than eight years of experience in design, development, and production support in SAP ERP. He has worked with SAP ERP implementations for industries such as chip manufacturing, healthcare, aviation, and computer hardware equipment. He has worked with SAP ERP modules in Sales and Distribution, Material Management, Plant Maintenance, Finance, and Project System. In the past, he has been part of some of the most challenging assignments including SAP implementations for Japan Airlines and General Motors. You may contact Vipin via email at [email protected].

    ABLE LABEL text in Figure 10.

    The H and V commands work the same as other examples. The $A command prints proportional spacing text. It requires three parameters separated by a comma. The first parameter 50 means

    font width in dots, the second parameter 50 means font height in dots, and the third parameter 8 means italic font. Figure 12 contains ABAP code that prints text as TRACEABLE LABEL on the output. This piece of code can be part of the report that was used to draw the