Thursday, December 20, 2007

Create Barcode in ABAP : conversion to PDF

INTRODUCTION

This document describes a Barcode solution implemented in ABAP to generate/print barcodes . The project is totally developed in ABAP and it can be used with any SAP solution and version.



SYMPTOM

There're differents solutions for the creation and print BARCODEs . All of them have the same problem : When you create a spool from a form/smartform with Barcodes, it's not possible to convert the spool to a PDF file because the BARCODE is created at the time of printing .

See Notes OSS : 430887 , 645158



SOLUTION

This solution is totally developed in ABAP . It runs for any SAP ( and O.S. ) because it's a library and function module for the barcodes creation .

Output is a data table within the barcode coordinates . You can use this coordinates to create a Barcode in a form/smartform seeing the correct Barcode image when you display the form.

It's possible to generate automatically others types of file ( using CONVERT_OTF from spool to PDF ) .
Others outputs could be HTML format or Java Bitmap , always using the barcodes coordinates ( not developed yet ) .

The process can be executed on-line and batch .

ADVANTAGEDISADVANTAGE
It can be use with any O.S. and SAP version .It can’t be use for a SAP-Reports .
It can be use with any printer connected to SAP.
Output to form/smartform ( PDF ) , data table ( it’s possible to format to HTML , Java-Bitmap )
Free solution


BARCODE SPECS

You need a CODECS file for decode the string to Barcode coordinates . CODECS have the definition of each barcode font and his map with each ASCII char.

These are the font codes implemented and tested :

FONTSUB-SETCHECKSUMCODECSTEST
Code 128AYesC128Intermec CK31/1551
Code 128BYesC128Intermec CK31/1551
Code 128CYesC128Intermec CK31/1551
Code 39
Yes/NoC39Intermec CK31/1551
Code 93
YesC93Intermec CK31/1551
EAN 8
YesEAN13
EAN 13
YesEAN13Intermec CK31/1551
EAN 14Font C128YesC128Intermec CK31/1551
CODABAR
NoCODABARIntermec CK31/1551
UPC/EANA
UPCEAN
UPC/EANE
UPCEAN


CODECS File :



Links
http://www.barcodesymbols.com/symbologies.htm
http://www.jtbarton.com/Barcodes/Code128.aspx
http://www.barcoderesource.com/code39_barcode_map.html
http://grandzebu.net/index.php?page=/informatique/codbar-en/code128.htm
http://www.barcodeman.com/info/c39_1.php3
http://community.bartdesmet.net/blogs/bart/archive/2006/09/20/4459.aspx
http://www.barcodesymbols.com/ean13.htm





IMPLEMENTATION

Implementation of the library and functions modules has been developed in ABAP language in SAP 4.6 system , but it can run in any ABAP version ( supported by SAP ) .
To install is necessary to upload the code ( Z-include and Z-functions ) on SAP-system ans save file CODECS into SAP ( or local server ) .

1. Create Structure ZBARCODE_COORDS ( SE11 - Abap Dictionary - Data Type )
image


2. Create Include ZBARCODE_GENERATOR



3. Create Include ZBARCODE_FORMVIEWER



4. Create Function Module Z_BARCODE_CREATE


Input Parameters :

image


Table Parameters :

image


Global Data : include ZBARCODE_GENERATOR in global data (LZBARCODETOP)

image


Source Code of function module Z_BARCODE_CREATE :



5. CODECS file
Save the codecs file in the SAP Application Server or in your local PC . When you execute the function , you must inform the path in the input parameter.





MANUAL

Function Z_BARCODE_CREATE : you can use this function to create the Barcode coordinates

Parameters :

BARCODEinitial string
FONTtype of Barcode ( referenced to the table CODECS )
SUBSETsubset of Barcode ( referenced to the table CODECS )
CHECKSUMgenerate check code (flag)
ROTATERotate Barcode 90º (flag)
X_INIinitial X position
Y_INIinitial Y position
W_INIWeight of the image
H_INIHigh of the image
CODECSPATHCODECS file path
PATHSERVERtype of path ( P = presentation server / A = application server / T = Table )


Output table : Barcode coordinates of each black bar

X1X coordinate
Y1Y coordinate
W1Weight
H1High



Display the barcode in a SAPSCRIPT Forms or Smartforms : It depends on the window type of the Form you need to use differents PERFORMs developed in the ZBARCODE_FORMVIEWER include.

SAPSCRIPT => MAIN WINDOW : use PERFORM WRITE_FORM_BARCODE_MAIN . You need to create an element in the Main Window



SAPSCRIPT => VAR WINDOW : use PERFORM WRITE_FORM_BARCODE_VAR . In that case, you can't call to write many times at the same window ( because it isn't Main window ) . It's necesary create a SAPSCRIPT form with all the black bar ( max 500 bars ).



SMARTFORM : you have the internal table with the Barcode coordinates. Looping this table you can display the black bars in a Smartform.





EXAMPLES

This report display a sapscript form using the Z_BARCODE_CREATE function module and ZBARCODE_FORMVIEWER to display the form. If you print the form , you can convert the sap-spool to the PDF file using CONVERT_OTF function module.

PDF generated from SAP-SPOOL :

image

Source Code Z_BCTEST :



Form Z_BCTEST (SE71): Create a sapscript form Z_BCTEST with a MAIN window. Include the BARCODE element into the main window.






No comments:

Blog Archive