Skip to Content
author's profile photo Former Member
Former Member

How to print a barcode using ABAP

Hi,

Could you please provide me with a sample code for prinitng a bar code on the report output??

Appropriate points will be rewarded

Regards,

Mansi.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Jun 18, 2008 at 10:39 AM

    Introduction

    With traditional bar code printing, the bar codes are generated at the printer and not in the SAP system. Special hardware, such as SIMM modules, is required to do this. If the bar code is to be formatted or controlled with traditional bar code printing, print controls must be changed in the printer commands.

    In contrast to traditional bar code printing, the new bar code printing does not require any special software, since the bar code is sent to the printer as a graphic. However, the new bar code printing only works with Smart Forms.

    1. Maintaining the Font(s)

    u2022 Go to TCODE SE73 and display the system bar codes,

    u2022 A default font (such as C128A shown below) can be used or you can create your own font

    Creating a new font

    u2022 Make sure you are in change mode for System bar codes

    u2022 Click on the New button on the toolbar and then choose the u2018New Bar Code Technologyu2019 and give it a name (eg: BC_NAME) and description

    u2022 Different barcode technologies are available. For this example we shall use u2018Code 128u2019

    u2022 Keep the other settings as default and save the font in a transport request (clicking on cancel at the transport request popup will save it locally)

    2. Creating the Style

    u2022 Go to transaction SMARTSTYLES or use the u2018Styleu2019 radio button of transaction SMARTFORMS

    u2022 Create a new Style (eg: ZBARCODE_STYLE)

    u2022 Create a default Paragraph Format by clicking on u2018Create Nodeu2019 from the Context Menu of u2018Paragraph Formatsu2019 in the left navigation view

    u2022 Create a new Character Format by clicking on u2018Create Nodeu2019 from the Context Menu of u2018Character Formatsu2019 in the left navigation view (I have given the Character Format the name u2018CHu2019 in this example)

    u2022 From the barcode name dropdown list, choose either a system default value such as C128A or the font that we just created (eg: BC_NAME)

    u2022 Save and activate the Style

    3. Creating the Smartform

    Here we will create a Smartform to display Material numbers from the MARA table as well as a barcode which contains that same Material number

    u2022 Go to transaction SMARTFORMS and create a new Smartform (ZBARCODE_MARA in this example)

    u2022 Create the following entry in the Tables tab of the Form Interface of your Smartform

    u2022 Save the Smartform

    u2022 Create a new Table entry on the Main Window as shown below

    u2022 In the Table tab of %TABLE1,Split the Line type %LTYPE1 into two parts

    u2022 In the Data tab, LOOP AT Internal Table IT_MARA INTO IT_MARA

    u2022 Create a Table Line in the header as well as the Main Area of the table

    u2022 Assign Line type %LTYPE1 to both of them

    u2022 Create a Text value in each of these four cells (you can rename them to make it easier to understand)

    Your left side navigation display should now look something like this

    u2022 Put appropriate headers into the HEADER_MATNR and HEADER_MATNR_CODE text fields

    u2022 Click on the Field list button to display the field list

    u2022 Drag and drop the MATNR field from the IT_MARA table interface into the General Attributes tab of the DATA_MATNR as well as the DATA_MATNR_CODE cells

    u2022 In the Output Options tab of the DATA_MATNR_CODE cell, choose the style that you created earlier (ZBARCODE_STYLE in this example)

    u2022 Go back to the General Attributes tab, select the text &IT_MARA-MATNR& and then change its character style to u2018CHu2019

    u2022 Save and activate the Smartform

    4. ABAP Program to call the Smartform

    u2022 Go to transaction SE38

    u2022 Create a simple program to call the Smartform

    u2022 Save, activate and run the program

    u2022 You can choose to preview or print the Smartform

    Sample program

    *&---------------------------------------------------------------------*
    *& Report  ZBARCODE_CALLER
    *&
    *&---------------------------------------------------------------------*
    *& call smart form
    *&
    *&---------------------------------------------------------------------*
    
    REPORT  ZBARCODE_CALLER.
    
    TABLES MARA.
    
    DATA FMNAME TYPE RS38L_FNAM.
    DATA ZITAB TYPE STANDARD TABLE OF MARA.
    
    SELECT MATNR FROM MARA INTO CORRESPONDING FIELDS OF TABLE ZITAB
      UP TO 15 ROWS.
    
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        FORMNAME = 'ZBARCODE_MARA'
      IMPORTING
        FM_NAME  = FMNAME.
    
    
    CALL FUNCTION FMNAME
      TABLES
        IT_MARA = ZITAB.
    
    

    5. Troubleshooting

    Consecutive bar-coded rows overlap

    Create a new paragraph format and set the Line Spacing to 2 Lines

    Use this new format in the non bar-coded cells

    Second field shows MATNR in English and not bar-coded

    Make sure you select the text before changing the character format in the Smartform

    Preview is proper but printing doesnu2019t take place at all

    Make sure your printer is configured properly in transaction SPAD. Try printing something else from SAP to verify the settings

    The device type used in our system is SAPWIN : Rel.4.x/SAPlpd 4.09+

    Also check the Print Immediately button, else go to transaction SP01 to immediately print all pending print jobs

    Preview is proper, text is printed properly but barcode (and pictures) are not proper

    Check that your printer is configured properly in Windows with the proper driver that matches your printeru2019s model

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 18, 2008 at 11:17 AM

    Now in SAP Wiki format...

    https://wiki.sdn.sap.com/wiki/display/profile/NewBarcodePrintinginSAPusingSmartforms

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 10:28 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 18, 2008 at 10:33 AM

    hi,

    u can create bar codes in SE73 transaction.

    check the table TFO05 - SAP bar codes

    reward points if hlpful.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 10:34 AM
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.