Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
10,151

Previously I covered a standalone method to introduce the Barcode Writer in Pure Postscript (BWIPP) into SAP smartforms and sapscript which can be found here Barcodes in SAP with the Barcode Writer in Pure Postscript.. That particular blog covered a method to introduce any one of the barcodes supported by the BWIPP into a SAP device type.

This blog demos extended use of the BWIPP and is in 3 sections

1) Barcode Sample Page. Generate barcodes by merging the BWIPP code with the SAP output stream on the desktop with free pdf software.

2) Generate custom barcodes with BWIPP and display them using the ABAP Bitmap class from Thomas Jung.

3) Using standard (free) GuiXT scripts to generate a barcode to display in Windows sapgui.

1) Barcode Sample Page

Below screen shot covers 26 barcodes on one page using ABAP print controls.

 

Here I cover a method by using desktop PDF software to merge the BWIPP into the SAP output stream on the desktop. This removes the need to install the BWIPP barcode postscript code into the device type. The only postscript code left in the device type controls how to use the BWIPP.

Follow this link to a Device Type I prepared earlier

The link points to a zip file containing a device type called ZBWIPP (ZBWIPP.PRI), a text file containing the ABAP code for the sample page (ZBWIPP_PRINT.TXT) and an output device ZBWIPP_ALL. Also the BWIPP barcode.ps file linked to the device type.

Postscript Device Type changes

Refer to the Barcodes in SAP with the Barcode Writer in Pure Postscript.for the technical details however what remains in the device type is the CREDITS action page. The main change to the code is to allow the barcode of choice to be defined in a variable. The ZBW01 printer control remains, however as shown below the printer controls change depending on which barcode is required.

The CREDITS action page postscript code is here...

The above code again controls how the BWIPP is used, and the main change from the previous blog is the line.

/sqrd {bcopt zzbc /uk.co.terryburton.bwipp findresource exec} def

This basically allows the barcode to be set by the device type's printer control. This is done with the zzbc variable.

As shown in this extract from my device type.

ZBW25 zbst
/zzbc (royalmail) def
bct sqrd
zben

The royalmail barcode would be selected with printer control ZBW25.

Options are shared among all barcodes.

ZOP03  /bcopt (includetext) def

So to use the option to include text in a barcode then ZOP03 would be used for all barcodes. Refer to the device type for the options already setup or the BWIPP wiki page for any other options required.

By removing the BWIPP code from the device type then it needs to be integrated at the printer ( a postscript printer may allow the BWIPP code to be uploaded to memory) or desktop. In this blog I will again cover the desktop PDF way.

*)PDFforge/PDFcreator

I now use PDFcreater which to quote "is free, even for commercial use" check out the website for further details.

The options to include the barcode.ps (which is the BWIPP)

By placing the barcode.ps in the additional parameters will allow the ghostscript call to process barcode.ps and the SAP postscript output to use the BWIPP.

*)CutePDF

You may have noticed the fact that barcode.ps is in the cutepdf directory in my screenshot. So you can do the same thing with cutepdf by creating a setup.ini file with the following contents for cutepdf.

[Parameters]
Command="C:program filesgsgs8.64 ingswin32c.exe"
Arguments=-q -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="%1" "C:Program FilesAcro SoftwareCutePDF Writer arcode.ps" -

The above example uses my ghostscript 8.64 version. Also as I am not sure how the above will be formatted in this biog, its 3 lines and the Arguments line ends with a -

 *)Note Ghostscript resource

The above config for the PDF software  (and in the other 2 sections below) is for a demonstration in this blog and uses ghostscript batch processing of postscript files to use the BWIPP. Ghostscript resources are normally found in a directory called Resource (parameter GenericResourceDir). In the download section of the BWIPP website refer to the README file in the tarball for use with Ghostscript. Using the resource directory method you could pick a combination of barcodes and not the entire barcode.ps file (and then remove the references to the barcode.ps in the above examples).

ABAP report for the 26 barcode sample page.

The sample page was produced using a standard ABAP report (ZBWIPP_PRINT.TXT in the zip file) with printer controls. I used the "new-page print on." command which is a depreciated command but it's the easiest way for me to demonstrate the wide range of barcodes supported by the BWIPP.

The report was done using page format X_65_80.

If you want to run the report then you need to have activated "print immediately"  for your SAP user account. The output device ZBWIPP_ALL in the download zip file in this blog is a frontend printer linked to the PDFCreator printer on the desktop.

There is a youtube video in the previous blog covering the use of BWIPP in smartforms and a link for sapscript.


2) Generate custom barcodes with BWIPP and display them in a Bitmap Class.

The next two methods were inspired by reading SDN and are on my demo SAP system.

I had the idea I was only a conversion (or two) away from getting an image bitmap of a barcode but how to display this in ABAP. I am not a developer but I was interested enough to search SDN for a possible answer. So I do start with how I found the main code to display a bitmap with ABAP.

While reading Blag's The specified item was not found., I read the webdynpro blog Web Dynpro ABAP: Display tiff images by bjorn-henrik.zink/blog who linked to Thomas Jungs blog Web Dynpro ABAP: Display tiff images. And who did thomas.jung/blog quote but full circle back to Blag. So thanks to all the links and contributions I did have some way to progress my idea.

I used Thomas Jung'sABAP Bitmap Image Processing Class and code for the ability to display bitmaps only. I was not intending to do any further processing. So why the bitmap class, well the main intention is to show a method to generate a custom barcode. Thomas Jung also provided the code for the bitmap class and example ABAP reports, so I was happy to use this to display the resulting bitmap image.

I have a newly installed demo SAP server so I added the code to generate barcodes (via sm49 commands) and upload via dataset commands controlled by the ABAP program. I am not an ABAP developer so it's the idea and not my (adapted from examples) code that I want to share. I would be happy to hear about alternate/better methods to show barcodes in ABAP (or if there are any issues with the approach I have taken). There are many ways to convert from postscript to a bitmap, and the following is obviously a demonstration of 1 way to do the conversion.

I was hoping to have a standalone barcode generator controlled via ABAP webdynpro and Thomas Jung includes ABAP webdynpro code however it remains a possible long term side project for me. 

A comment on my previous blog came from  Sergio Ferrari so I took the opportunity to contact him in regards to the general approach I was taking with the BWIPP. He pointed out his  abap2qrcode webdynpro code can accommodate different backend engines. So I downloaded and installed the code and from the structure of the webdynpro I can see the potential for using BWIPP. However developing in ABAP webdynpro is not in my plans. I appreciated Sergio's suggestions and encouragement to continue. Sergio also kept in touch in regards to sharing ideas and collaborating on mobile tagging in SAP and he is great at getting people involved. He made me aware of durairaj.athavanraja/blog's work related to mobile tagging and involved us all in the Wiki process. If you have any ideas/suggestions around the mobile tagging subject then please join in.

So adapting the classic ABAP dynpro example Thomas Jung provided, here is the screen shot of the options page.

 

 

Here is the QRcode result for the bitmap class weblog by Thomas Jung. ( I have downloaded the URL shortener on code exchange, but using that is for another day)

Another barcode this time ISBN barcode.

 Here is how I did it in general terms,

You will need the following,

*)BWIPP

*)ghostscript

*)imagemagick

All programs need to be in the PATH environment variable of the {SID}adm used

I placed all scripts in the work directory of my demo server.

Postscript Dataset options

Obviously we need to generate postscript code from the user supplied selections for the BWIPP to generate the required barcode.

Here is how I did this with the dataset command.....

concatenate '0 0 moveto (' text  ') (' options ') /' BARCODE ' /uk.co.terryburton.bwipp findresource exec' into TEXT1.
concatenate psX pSY  ' scale' into TEXT2.
OPEN DATASET psnm  FOR OUTPUT IN TEXT MODE ENCODING DEFAULT..
TRANSFER 'gsave' to psnm.
TRANSFER '50 50 translate' to psnm.
TRANSFER TEXT2 to psnm.
TRANSFER TEXT1 TO psnm.
TRANSFER 'grestore' to psnm.
TRANSFER 'showpage' to psnm.
CLOSE DATASET psnm.

 

text/BARCODE/psX/pSY are parameters for the selection screen. The BARCODE parameter needs to match the BWIPP. I used the  "CALL FUNCTION 'VRM_SET_VALUES'" code to use the drop down menu for the BARCODE selection (to ensure a valid selection).The postscript code for the position of the image is hard coded with the translate command. It's my choice you may need to experiment with the position of barcodes depending on the size and scaling options used for the barcode.

Barcode Generation with external commands

So now we have the postscript code we need to generate the barcode, here is the SM69/49 external scripts.

ZBWIPP external command defined in transaction SM69.

bat file sapbwipp.bat in the SAP work directory.

F:

cd usrsapNSPDEVEBMGS00work

copy barcode.ps+zsapbarcode.ps abaptemp.ps

ps2epsi abaptemp.ps out.eps & convert -density 85 out.eps BMP3:rob.bmp

 

Basically the above dos bat file takes the dataset of the barcode options and merges this with the barcode.ps file.

ps2epsi is key to generate what is known as an encapsulated postscript file (EPS). The EPS conversion is required to allow only the image of the barcode to be processed further and not the entire page. (ps2epsi is a script with ghostscript)

convert is imagemagick doing its magic to convert the EPS file to a bmp file. Now it may or may not be the case of a convert issue with Windows systems depending on the PATH environment variable. e.g. convert is also a system command so check out this link on the image magick site for this convert issue. It would be useful to test the conversion purely on the operating system to check PATH variables or any other issues.

Density actions need to be confirmed for any requirements. 2d barcodes can work with lower density settings however text in some 1d barcodes required higher density to be clear in the bitmap. More info can be found with this link to the image magick site here

The BMP3 option was my solution to actually see an image in the bitmap class, the reason I tried the option BMP3 is in this link.

The way I used ABAP to run the external command is here in the WIKI, it's a Unix related page however the ABAP code is what I required for my windows based sm49 commands.

CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
  EXPORTING
    commandname                   = 'ZBWIPP'
*   additional_parameters         = v_dir_input
*   operatingsystem               = c_oper
  TABLES
    exec_protocol                 = t_result
  EXCEPTIONS
    no_permission                 = 1    .....there is more so see the wiki page......

Bitmap Image Dataset options

 I knew I had to upload a binary file, so I started with this search however, I can't recall the exact search options I finally used but  I got the following for the dataset options from this another image question - using Regular ABAP not web dynpro

 IF bitmap IS INITIAL.
    TRY.
 DATA: lv_ds TYPE string VALUE 'rob.bmp',
             lv_xstring TYPE xstring.
  OPEN DATASET lv_ds FOR INPUT IN BINARY MODE .
  CHECK sy-subrc = 0.
    READ DATASET lv_ds INTO lv_xstring.

Display the Barcode
Thankfully Thomas Jung had put some comments into his blog covering his code, so I could swap out the frontend upload and use the xstring from the dataset.

*   bitmap = zcl_abap_bitmap=>create_from_frontend_upload( ).
bitmap = zcl_abap_bitmap=>create_from_bytestream( lv_xstring ).
        bitmap->display_in_sapgui(
             i_container = custom_container ).
      CATCH zcx_abap_bitmap .
    ENDTRY.
  ENDIF.
ENDMODULE.                 " STAT

The barcode image file is hardcoded in the code above and no unique file names are used for the temporary files. However the image file is created on the filesystem.

Now all the above lead to me to a demo with GuiXT

3) Windows SAPGUI barcodes with standard GuiXT

 GuiXT in its standard form allows scripts to run to display images.

So using the same scripts as above with some slight modification we can generate a QR code with MEcard formatted data as below. It is a demo and only uses the postcode and other items for demonstration purposes. I had already tried scanning a MEcard Generating QR codes with a Zebra Crossing in the Java stack, so I thought SAP could generate one on the desktop.

 

So taking the business partner transaction (/nBP). The guixt script will call one dos bat file which in turn will call a dos bat script to generate the barcode image. This example uses QRcodes, however it could obvioulsy be one of the BWIPP supported barcodes depending in requirements.

You need to know the directory used by GuiXT which is normally guixt  (or guixt/scripts). The following examples are hardcoded with c:GuiXT. In the GuiXT directory place the barcode.ps file (in this example I renamed the file to blogging.ps). Again both ghostscript and imagemagick programs need to be in the PATH environment variable of the user.

In c:GuiXT folder create a directory called img

Create a text file with the name SAPLBUS_LOCATOR.e3000.txt

if Q[Page=Address]

Pushbutton (toolbar) "Refresh Screen for QRcode" "/0"

image (19,130) "c:GuiXTimg&F[ADDR1_DATA-POST_CODE1].jpg" "-NoBuffer" "-Transparent" "-Plain" exe="C:GuiXTstartstatic.bat &F[ADDR1_DATA-POST_CODE1] ""&F[T005T-LANDX]"" ""&F[BUT000-NAME_ORG1]"" ""&F[SZA1_D0100-TEL_NUMBER]""" start="C:GuiXTstartstatic.bat &F[ADDR1_DATA-POST_CODE1] ""&F[T005T-LANDX]"" ""&F[BUT000-NAME_ORG1]"" ""&F[SZA1_D0100-TEL_NUMBER]"""


endif

This file in its current form would be active for any BP transaction on any system. The toolbar pushbutton "/0" emulates a return command so best for display only transactions. It uses the post code and address details of the business partner and calls script startstatic.bat. The image would only be displayed on the Address tab which is set by the if Q[Page=Address] line. The exe= executes the dos bat file to load the image. The start= command runs if the image icon is clicked by the user to refresh the image with the toolbar pushbutton option.

The GuiXT image command is used to call the following dos script.

Script C:GuiXTstartstatic.bat

@ECHO OFF

cd c:guixt

del /Q c:GuiXTimg\%1%.jpg"

set LAND=%2
set LAND=%LAND: =+%

set NAME=%3
set NAME=%NAME: =+%

start /min c:GuiXTstaticnew.bat %1 %LAND% %NAME% %4

exit

The above replaces all spaces in the variables with a plus +. This was useful for some simple url encoding I was doing. The start command is used to run the next script c:GuiXTstaticnew.bat in a minimised window.

Script c:GuiXTstaticnew.bat

C:
cd  guixt
set LAND=%2
set LAND=%LAND:"= %
set NAME=%3
set NAME=%NAME:"= %
echo gsave >temp.ps
echo 50 50 translate >>temp.ps
echo 2 2 scale >>temp.ps
echo 0 0 moveto (MECARD:N:%NAME%;ADR:%1,%LAND%;TEL:%4;) () /qrcode /uk.co.terryburton.bwipp findresource exec >>temp.ps
echo grestore >>temp.ps
echo showpage >>temp.ps
gswin32c -sDEVICE=epswrite -q -dBATCH -dNOPAUSE -sOutputFile=out.eps blogging.ps temp.ps
convert -density 80 out.eps .img\%1.jpg

 

The earlier idea of using the ABAP bitmap class lead me to this point and similar scripts to create the barcode. E.g. ghostscript creates the EPS file and imagemagick creates the image. This time I use ghostscript's epswrite device to get the encapsulated postscript file. Imagemagick is used to create a jpg file so guixt can use the file. The barcode.ps is renamed blogging.ps in the above example.

One final idea

Ok I was having some fun. So I carried on and put the ABAP code above with modifications for a BSP application (create/load via the same dataset commands and use the cache to redirect to the image). Then controlled the whole thing from Excel,  demo in this youtube video here. The video shows barcodes being created from the contents of the cells in Excel, and then I adjust the scale of the barcode in the backend BSP which is generating the barcodes for Excel.

11 Comments