【转载】 SAP 打印二维码 QR Code or 2D Bar Code in SAP

S4 不需要打NOTE,测试通过。

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

Step 1: Upgrade the Kernel if Required

 

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

 

SS01.png

 

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

 

SS02.png

SS03.png

 

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.

 

SS04.png

SS05.png

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.

SS01.png

 

Click on Create(F5).

SS02.png

 

Click on New (new Barcode Technology)

SS01.png

Define the Name and Description of the Bar code.

SS01.png

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

 

SS01.png SS01.png

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

SS01.png

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

SS01.png

 

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,

      w            TYPE i,

      h            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  <fs>   type x.

 

clear: hex, bitmap3.

loop at otf.

  length = otf-tdprintpar+2(2).

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

  hex = <fs>(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

SS01.png

SS01.png

Define the QR Code in Character Format as below Screenshot

 

SS01.png

 

Step 6: Use SmartStyle in SmartForm

 

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

SS01.png

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

 

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

SS01.pngSS01.png

Test The SmartForm

 

SS01.png SS01.png

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.

<think>好的,我现在需要帮助用户在SAP系统中实现打印包含汉字的二维码。根据用户提供的引用内容,特别是引用[3]提到的二维码编码原理和示例,以及引用[2]提到的SAP结合大语言模型和知识图谱的生成式AI应用,我需要综合这些信息来构建解决方案。 首先,我应该确认SAP系统是否支持直接生成二维码,特别是包含汉字的情况。用户提到的引用[2]提到SAP有图谱API,可能可以利用这些API来处理汉字编码。但可能还需要结合第三方库或者工具,因为SAP本身可能不直接支持二维码生成。 然后,汉字编码需要遵循特定的标准,比如UTF-8或者GBK,确保生成的二维码能够正确存储和显示汉字。引用[3]中的示例使用的是二进制编码,所以需要将汉字转换为相应的二进制数据,并按照二维码的标准格式进行编码。 接下来,考虑如何在SAP中实现打印功能。可能需要使用SAP的Script或Smart Forms来设计打印格式,将生成的二维码图像嵌入到打印输出中。这里可能需要调用外部程序或使用ABAP代码生成二维码图片,再将其插入到打印文档中。 另外,用户提到的PB二维码生成工具(引用[1])虽然基于PowerBuilder,但可能提供一些思路,比如集成第三方库。在SAP中,可能需要类似的集成方式,比如使用ABAP调用外部库或API来处理二维码生成和汉字编码。 需要注意的问题包括:确保SAP环境有必要的权限调用外部资源,处理汉字编码时的字符集转换,以及生成的二维码是否符合打印尺寸和质量要求。此外,测试不同扫描设备对包含汉字的二维码的识别能力也很重要,确保兼容性。 可能还需要查阅SAP官方文档或社区资源,看看是否有现成的教程或组件可以直接使用。引用[2]提到的生成式AI课程可能提供一些开发思路,尤其是结合SAP的数据处理能力来动态生成二维码内容。 总结步骤大致为:处理汉字编码、生成二维码图像、集成到SAP打印模块。每个步骤都需要详细的技术实现,可能需要编写ABAP代码,调用外部库,或者使用SAP的API服务。</think>在SAP系统中实现打印包含汉字的二维码需要综合处理编码、生成和打印三个关键环节。以下是分步实现方案: --- ### 一、汉字编码处理 1. **确定字符集标准** 汉字需使用支持中文的字符集,如UTF-8或GB18030。在ABAP中可通过`CL_ABAP_CONV_OUT_CE`类进行编码转换: ```abap DATA(lv_utf8_data) = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' )->convert( lv_chinese_text ). ``` 引用[3]中提到的二进制编码需确保转换后的字节流符合二维码规范。 2. **编码模式选择** 二维码支持多种编码模式(如数字、字母、字节流)。汉字需使用**字节模式(Byte Mode)**,并将UTF-8编码后的二进制数据嵌入二维码。 --- ### 二、二维码生成 1. **使用第三方库集成** SAP原生不支持二维码生成,需通过以下方式实现: - **调用外部API**:通过HTTP服务调用在线生成接口(如ZXing API)。 - **集成开源库**:在ABAP中嵌入ZXing或QRCodeLib的Java库(需配置JCo连接)。 - **自定义生成算法**:参考引用[3]的编码原理,实现Reed-Solomon纠错等核心逻辑(复杂度较高)。 2. **示例代码(通过Java库调用)** ```abap DATA(lo_java_qr) = NEW CL_JAVA_QRCODE_GENERATOR( ). lo_java_qr->set_text( lv_utf8_data ). lo_java_qr->set_size( 200 ). "设置尺寸 DATA(lv_image) = lo_java_qr->generate( ). "生成图片二进制流 ``` --- ### 三、SAP打印集成 1. **使用Smart Forms或Adobe Forms** 将二维码图像嵌入打印模板: - 在Smart Forms中创建图形节点,绑定生成的`lv_image`二进制流。 - 通过`SSFCOMP`函数组合表单数据。 2. **直接输出到打印机** 使用`WRITE_FORM`或`OPEN_FORM`函数将包含二维码的文档发送至打印机,需确保打印机支持图像渲染。 --- ### 四、关键注意事项 1. **编码验证** 使用在线解码工具(如草料二维码)测试生成的二维码是否可正确识别汉字[^3]。 2. **性能优化** 高频生成时建议预生成二维码并存储为BDS文档,避免实时计算延迟。 3. **权限与依赖** 确保SAP服务器具有访问外部API或执行Java代码的权限[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值