This post covers a straight forward BSP and a simple Excel Macro to generate barcodes. By straight forward and simple I mean that I dont go into any error checking :) Also as I have covered Yahoo maps previously then its a case of changing the Excel Macro slightly to pick up the Yahoo static map images, however as Yahoo terms of use are involved then its only a demo. The barcodes covered first are free though :).
First the barcode related BSP.
Goto Se80 and create a BSP called ZBWIPP
Create a page bc.htm with the following
Attributes, barcodes, options and text as shown below.
The Event Handler "OnInitialization" code takes the url parameters and generates the barcodes. See the "More Barcodes with Barcode Writer in Pure Postscript" post for the requirements for ghostscript and imagemagick. The external commands line
CALL FUNCTION 'SXPG_COMMAND_EXECUTE' uses the same code in the SDN blog for the script
ZBWIPP. Also all the scripts and barcode.ps code are in the work directory of my SAP demo 702 server.
navigation->set_parameter( 'text' ).
navigation->set_parameter( 'barcode' ).
navigation->set_parameter( 'options' ).
*DATA bitmap TYPE REF TO zcl_abap_bitmap.
DATA okcode TYPE syucomm.
DATA filed type string.
DATA: t_result TYPE STANDARD TABLE OF btcxpm.
DATA psX type string.
DATA psY type string.
data scaleX type i.
data scaleY type i.
data bit TYPE XSTRING.
data display_url type string.
*the scale values could be placed in the excel call also, not done it yet
scaleX = 2.
scaleY = 2.
data p_name type string.
if text is initial.
text = 'no text detected'.
endif.
if barcode is initial.
barcode = 'datamatrix'.
endif.
psX = scaleX.
psY = scaleY.
DATA: psnm TYPE string VALUE 'f:\usr\sap\NSP\DVEBMGS00\work\zsapbarcode.ps'.
DATA: barc TYPE string VALUE 'f:\usr\sap\NSP\DVEBMGS00\work\rob.bmp'.
DATA: TEXT1(255),
TEXT2(20),
LENG TYPE I.
* 0 moveto (2310844"Japan") () /qrcode /uk.co.terryburton.bwipp findresource exec
*howpage
*concatenate '50 50 moveto (' text ') (' options ') /' barcode ' /uk.co.terryburton.bwipp findresource exec' into TEXT1.
concatenate '50 50 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.
*RANSFER '50 50 moveto' to psnm.
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.
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
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
OTHERS = 15.
OPEN DATASET barc FOR input IN BINARY MODE.
READ DATASET barc INTO bit.
CLOSE DATASET barc.
IF XSTRLEN( bit ) > 0.
DATA: cached_response TYPE REF TO if_http_response.
CREATE OBJECT cached_response TYPE CL_HTTP_RESPONSE EXPORTING add_c_msg = 1.
cached_response->set_data( bit ).
cached_response->set_header_field( name = if_http_header_fields=>content_type
value = 'image/bmp' ).
cached_response->set_status( code = 200 reason = 'OK' ).
cached_response->server_cache_expire_rel( expires_rel = 180 ).
DATA: guid TYPE guid_32.
CALL FUNCTION 'GUID_CREATE' IMPORTING ev_guid_32 = guid.
CONCATENATE runtime->application_url '/' guid '.bmp' INTO display_url.
cl_http_server=>server_cache_upload( url = display_url
response = cached_response ).
***response->redirect( display_url ).
response->redirect( display_url ).
else.
response->redirect( 'http://himble.test.com:8000/sap/bc/bsp/sap/zbwipp/zbwipperror.bmp' ).
endif.
SIMPLE EXCEL MACRO
The excel macro is really simple in that it uses the current selection and uses offsets to pick up the required barcode, options and text. So for example the required barcode would be in column A, the options in column B and the text for the barcode would be in column C. The range to select would be in column E, my choice.
Sub zbwipp()
Dim barcode As String
Dim text As String
Dim options As String
For Each Cell In Selection
Cell.Select
barcode = Cell.Offset(0, -4).Value
options = Cell.Offset(0, -3).Value
text = Cell.Offset(0, -2).Value
' MsgBox barcode
ActiveSheet.Pictures.Insert( _
"http://himble.test.com:8000/sap/bc/bsp/sap/zbwipp/bc.htm?barcode=" + barcode + "&options=" + options + "&text=" + text).Select
Next Cell
End Sub
The result in a YouTube Video
Yahoo Static Map Images
If the Excel command
ActiveSheet.Pictures.Insert is used to point to the Yahoo BSP in this post then static maps can be generated as shown below. The same location is used in my home town of Birmingham and the width of the image is changed and the static maps generated.
No comments:
Post a Comment