Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to print a barcode using ABAP

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

former_member189059
Active Contributor
0 Kudos

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

5 REPLIES 5

GauthamV
Active Contributor
0 Kudos

hi,

u can create bar codes in SE73 transaction.

check the table TFO05 - SAP bar codes

reward points if hlpful.

former_member189059
Active Contributor
0 Kudos

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

former_member189059
Active Contributor
0 Kudos

Now in SAP Wiki format...

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