Smartform 打印二维码 …

QR Code or 2D Bar Code in SAP

 

 

原文地址 https://blogs.sap.com/2016/05/12/qr-code-or-2d-bar-code-in-sap/

 

Hi Gurus,

I have came across requirement of Printing QR Code (Quick Response Code) or 2D Bar Code on Smartforms or Download it as an Image file.

Here, I am going to explain "How it can be done?"

Step 1: Upgrade the Kernel if Required

Log in to the SAP >> SAP Easy Access Screen >> System Menu >> Status

Now, Click on the component to check the SAP_BASIS release 731

Close the pop-up dialog and click on the arrow button. The Kernel Version Should be 321 or superior. If it is not then ask your Basis Team to upgrade it.

Step 2: Implement SAP Note 2029824

Ask the Developer to implement the note

2029824 – Support for QR code and data matrix bar code

 

Step 3: SAP Script Font Maintenance

After successful implementation of the SAP Note. Go to Transaction SE73.

Click on System Bar Code option and Click on Change.

Click on Create(F5).

Click on New (new Barcode Technology)

Define the Name and Description of the Bar code.

Select Bar Code Symbology as "QR Code 2005" and Click OK. Select Alignment as "Normal"

   

Choose Mode, Module Size, Error Correction Level (Refer the SAP note 2030263 for further information)

Mode:

A – AUTOMATIC

N – NUMERIC

L – ALPHANUMERIC

B – BYTE_LATIN1

K – KANJI

U – BYTE_UTF8

1 – FNC1_POS1 (FNC1 in first position)

2 – FNC1_POS2 (FNC1 in second position)

Module Size: Numeric User Entry

Error Correction Level:

L – 7 % Error Correction capability

M – 15% Error Correction capability

Q – 25% Error Correction capability

H – 30% Error Correction capability

Save the Bar Code Definition. Select the same and Test.

Step 4: Create Program to Download the QR Code as BMP (image File)

Write the below code in the SE38 Program. This Program can download the QR Code as image (.bmp format) on your presentation system.

*YOTQR starts

*&———————————————————————*

*& Report  YOTQR2 this program dirctly print BMP file of any barcode

*&

*&———————————————————————*

*&

*&

*&———————————————————————*

REPORT YOTQR.

PARAMETERS: barcode like tfo05-tdbarcode default 'ZQRCODE',

            barcdata(50) type c lower case default '1234567890',

            filename type string LOWER CASE default 'd:\1.bmp'.

DATA:errmsg(80)   TYPE c,

      bc_cmd       LIKE itcoo,

      bp_cmd       LIKE itcoo,

      bitmapsize   TYPE i,

      bitmap2_size TYPE i,

                TYPE i,

                TYPE i,

      bitmap       LIKE rspolpbi OCCURS 10 WITH HEADER LINE,

      bitmap2      LIKE rspolpbi OCCURS 10 WITH HEADER LINE,

      l_bitmap     TYPE xstring,

      otf          LIKE itcoo OCCURS 10 WITH HEADER LINE.

PERFORM get_otf_bc_cmd  IN PROGRAM sapmssco

                       USING barcode

                             barcdata

                             bc_cmd.

CHECK sy-subrc = 0.

bp_cmd-tdprintcom = 'BP'.

PERFORM get_otf_bp_cmd  IN PROGRAM sapmssco

                       USING barcode

                             bp_cmd-tdprintpar.

CHECK sy-subrc = 0.

PERFORM renderbarcode IN PROGRAM sapmssco

                     TABLES bitmap

                      USING bc_cmd

                            bp_cmd

                            barcdata

                            bitmapsize

                            w

                            h

                            errmsg.

CHECK sy-subrc = 0.

perform bitmap2otf IN PROGRAM sapmssco

                   tables bitmap

                          otf

                    using bitmapsize

                          w

                          h.

data length type i.

data hex type xstring.

data bitmap3 type xstring.

FIELD-SYMBOLS     type x.

clear: hex, bitmap3.

loop at otf.

  length = otf-tdprintpar+2(2).

  assign otf-tdprintpar+4(length) to casting.

  hex = (length).

  concatenate bitmap3 hex into bitmap3 in BYTE MODE.

endloop.

* convert from old format to new format

hex = 'FFFFFFFF01010000'.

CONCATENATE bitmap3(8) hex bitmap3+8 into bitmap3 in BYTE MODE.

clear hex.

shift hex right by 90 places in BYTE MODE.

CONCATENATE bitmap3(42) hex bitmap3+42 into bitmap3 in BYTE MODE.

data bitmap4 type SBDST_CONTENT.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

    EXPORTING

      buffer                = bitmap3 " xstring

    TABLES

      binary_tab            = bitmap4.

data bitmap4_size type i.

bitmap4_size = xstrlen( bitmap3 ).

CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'

EXPORTING

   OLD_FORMAT                     = 'BDS'

   NEW_FORMAT                     = 'BMP'

   BITMAP_FILE_BYTECOUNT_IN       = bitmap4_size

IMPORTING

   BITMAP_FILE_BYTECOUNT          = bitmap2_size

  TABLES

    bitmap_file                    = bitmap2

   BDS_BITMAP_FILE                = BITMAP4

EXCEPTIONS

   NO_BITMAP_FILE                 = 1

   FORMAT_NOT_SUPPORTED           = 2

   BITMAP_FILE_NOT_TYPE_X         = 3

   NO_BMP_FILE                    = 4

   BMPERR_INVALID_FORMAT          = 5

   BMPERR_NO_COLORTABLE           = 6

   BMPERR_UNSUP_COMPRESSION       = 7

   BMPERR_CORRUPT_RLE_DATA        = 8

   BMPERR_EOF                     = 9

   BDSERR_INVALID_FORMAT          = 10

   BDSERR_EOF                     = 11.

  CALL METHOD cl_gui_frontend_services=>gui_download

    EXPORTING

      bin_filesize = bitmap2_size

      filename     = filename

      filetype     = 'BIN'

    CHANGING

      data_tab     = bitmap2[]

    EXCEPTIONS

      OTHERS       = 3.

*YOTQR Ends

 

Step 5: Create Smartstyle for QR Code

Define your Smartstyle as below screenshots

Define the QR Code in Character Format as below Screenshot

Step 6: Use SmartStyle in SmartForm

 

Define the smartstyle in the form attributes as per the below screenshot

Define Text as below screenshots. Caution: keep the (small letters) not (capital Letters) otherwise QR code will not get Printed)

in this example, I've used material Number to be encoded in QR Code.

Test The SmartForm

 

   

We can use the same procedure to include the QR code on your SmartForms.

This Bar Code can encode up to 255 characters (it is the limit).But, I think, 255 characters enough.

 

Using this you can shrink the size of your label. You can encode the address information as QR Code and save the space on the form for more details and many more.

 

END

本人测试结果


最后,感谢群内同行 笙筠  提供的信息链接。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 首先,在ALV的程序里面定义一个新的按钮,用于触发打印操作。 2. 在按钮的事件处理中,调用函数 module_name = 'SSF_FUNCTION_MODULE_NAME',获取Smartform的函数模块名。 3. 然后,通过函数 module_name = 'SSF_FUNCTION_MODULE_NAME' 获取的函数模块名,调用函数 module_name,传入需要打印的数据。 4. 最后,调用函数 'SSF_FUNCTION_MODULE_NAME',传入Smartform的函数模块名和需要打印的数据,即可完成打印操作。 以下是示例代码: 1. 定义按钮 DATA: ok_code TYPE sy-ucomm. CASE ok_code. WHEN 'PRINT'. lv_layout-info_fname = 'ZALV_SMARTFORM'. CALL METHOD cl_gui_alv_grid=>get_selected_rows RECEIVING value = lt_sel. LOOP AT lt_sel INTO ls_sel. READ TABLE gt_outtab INTO ls_outtab INDEX ls_sel-index. APPEND ls_outtab TO lt_print. ENDLOOP. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = lv_layout-info_fname IMPORTING fm_name = lv_fm_name. CALL FUNCTION lv_fm_name EXPORTING control_parameters = gt_cparams output_options = gt_oparams user_settings = gt_usparams TABLES t_outtab = lt_print. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = lv_layout-info_fname IMPORTING fm_name = lv_fm_name EXCEPTIONS no_form = 1 no_function_module = 2 others = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. CALL FUNCTION lv_fm_name EXPORTING control_parameters = gt_cparams output_options = gt_oparams user_settings = gt_usparams TABLES t_outtab = lt_print. ENDIF. ENDCASE.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值