Preparing SAP data to be printed as a linear barcode can be a pain at times; when 2D barcodes with proper field separators are required the pain factor goes up. Most of the problems come from trying to convince SAP to assign non-printing control characters to the output variable. So, I have written a small example which demonstrates both how to generate a PDF417 barcode and the steps required to assign special characters to a string in ABAP. SAPscript cannot handle 2D barcodes, so this code will only really work in SmartForms.

DATA: gv_pdf417 TYPE string,
      gv_date_old TYPE likp-wadat,
      gv_serial TYPE num9,
      gv_kdmat TYPE vwahn-kdmat,
      gv_meng TYPE char10,
      lf_masterorsingle TYPE char3,
      lf_hex_rs TYPE x LENGTH 4 VALUE '001E',
      lf_hex_gs TYPE x LENGTH 4 VALUE '001D',
      lf_hex_eot TYPE x LENGTH 4 VALUE '0004',
      lf_char_rs TYPE c,
      lf_char_gs TYPE c,
      lf_char_eot TYPE c.
FIELD-SYMBOLS: <lfs_rs>,
               <lfs_gs>,
               <lfs_eot>.

WRITE is_wahn-wadat TO gv_date_old yymmdd.
WRITE is_wahn-exidv+11(9) TO gv_serial.

" Get non-printing control characters set
ASSIGN lf_hex_rs TO <lfs_rs> CASTING TYPE c.
ASSIGN lf_hex_gs TO <lfs_gs> CASTING TYPE c.
ASSIGN lf_hex_eot TO <lfs_eot> CASTING TYPE c.
lf_char_rs = <lfs_rs>.
lf_char_gs = <lfs_gs>.
lf_char_eot = <lfs_eot>.

" Master or single label
IF is_wahn-zzmastersingle = 'M'.
        lf_masterorsingle = 'M'.
ELSE.
        lf_masterorsingle = 'S'.
ENDIF.

CONCATENATE
  '[)>' lf_char_rs
  '06' lf_char_gs
  'P' gv_kdmat lf_char_gs
  'Q' gv_menge lf_char_gs
  'V' gv_lifnr lf_char_gs
  'D' gv_date_old lf_char_gs
  lf_masterorsingle gv_serial
  lf_char_rs lf_char_eot
  INTO gv_pdf417.


If all goes well, then the variable gv_pdf417 should contain a string like the one below (the characters in the angle brackets are the hex codes for the control characters). In SmartForms the variable should be output in a text area with using the PDF417 barcode character formatting (your basis team will have to install it if it is not already available). The barcode at the top of page is generated from the string below.

[)><1E>06<1D>Pcccc cccc cc<1D>Qnn<1D>cccccc<1D>Dyymmdd<1D>Mnnnnnnnnn<1E><04>

Comments (newest first)

kamber
What is the 'is_wahn' field ?

Tags: Blogger Barcodes SmartForms SAP Code ABAP

Published: 2012-06-30