打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使用ABAP代码生成二维码(QR Code)

Previously we have discussed how to generate QRcode with SAP standard functionality:

(1) Generate QRcode with ABAP Webdynpro (2) Generate QRcode with ABAP Code plus Adobe form template

Both solutions will generate QRCode within a PDF file.

If your requirement is to generate the QRCode in a picture file, you can use the solution described in this blog.

There are lots of websites which provide free QRCode generation service. Just google it:

I prefer to use this one http://www.qrstuff.com: just choose “Plain Text” and we can input some characters in Text field. There is a AJAX call which will generate QRCode immediately after some characters are typed.

te (二维码自动识别)

Now question is how we automate the character input via ABAP.

I use Chrome to explore what has happened when we input some char in webpage. Click F12 to launch Chrome developer tool, input some char and observe the information displayed in the “Network” tab:

test (二维码自动识别)

The request URL is found: http://www.qrstuff.com/generate.generate The request method is GET. Also it is necessary to identify http form fields and they are also listed in Chrome:

We need to copy all of those form fields into our ABAP code except preview=1, since we don’t need the preview functionality, we just need the generated png file.

here below is the simple report to generate QRCode from hard coded string “testforQRCode”. ( The bold text are just copied from Chrome developer tool ) The source code of zcl_http_tool could be found from attachment.

DATA:ls_form   type zcl_http_tool=>ty_name_pair,     lt_form   type zcl_http_tool=>tt_name_pair,     lv_code   type xstring.ls_form = value #( name = 'type' value = 'TEXT' ).APPEND ls_form TO lt_form.ls_form = value #( name = 'foreground_color' value = '000000' ).APPEND ls_form TO lt_form.ls_form = value #( name = 'ecc_level' value = 'L' ).APPEND ls_form TO lt_form.ls_form = value #( name = 'width_pixels' value = '200' ).APPEND ls_form TO lt_form.ls_form = value #( name = 'dpi' value = '72' ).APPEND ls_form TO lt_form.ls_form = value #( name = 'file_type' value = 'png' ).APPEND ls_form TO lt_form.ls_form = value #( name = 'text' value = 'testforQRCode' ).APPEND ls_form TO lt_form.zcl_http_tool=>send_request( EXPORTING iv_url      = 'http://www.qrstuff.com/generate.generate'                                       iv_req_type = if_http_request=>co_request_method_get                                       it_form     = lt_formIMPORTING ev_response = lv_code ).

And this is QRCode scanned from my mobile phone:

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
11个python列表方法全面解析
通过AMDP调用HANA的PAL函数
用QRCode生成带有中间logo图的二维码
tp5.1生成二维码
ABAP 程序完成EXCEL文件的导入导出
如何用.NET生成二维码?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服