‎2019 Feb 26 12:11 PM
Hi everyone,
I have a requirement to convert barcode to qr code and I have used the code from the link https://blogs.sap.com/2013/10/15/how-to-create-a-qr-code-and-show-it-in-a-smartform/
I have written the perform in the Form Routines tab in the smartform.
Inside Program lines under main Window:
DATA: l_img_url TYPE w3url.
DATA :l_img_subtype TYPE W3CONTTYPE. "w3param–cont_type.
DATA : l_str_length TYPE i.
*DATA : url TYPE string.
DATA : l_content_length TYPE i.
DATA : mime TYPE w3mimetabtype.
DATA: blob TYPE w3mimetabtype,
blob_size TYPE W3CONTLEN,
blob_type TYPE W3CONTTYPE.
DATA : i_igs_image_converter TYPE REF TO cl_igs_image_converter.
DATA: content TYPE xstring.
DATA : http_client TYPE REF TO if_http_client.
* Asset details
CLEAR g_barcode.
CONCATENATE gs_final-bukrs " Company code
gs_final-anln1 " Asset code
gs_final-txt50 " Asset Desc.
gs_final-aktiv " Capitalisation Date
gs_final-stort " Asset Location
gs_final-kostl " Cost Center
INTO g_barcode SEPARATED BY '_'.
*g_barcode = gs_final-anln1.
CONCATENATE 'http://chart.apis.google.com/chart?chs=200×200&cht=qr&chld=|1&chl=' g_barcode '/chart.png' INTO url.
BREAK-POINT.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = url
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc = 0.
http_client->send( ).
http_client->receive( ).
content = http_client->response->get_data( ).
http_client->close( ).
l_str_length = xstrlen( content ).
CALL FUNCTION 'RSFO_XSTRING_TO_MIME'
EXPORTING
c_xstring = content
i_length = l_str_length
TABLES
c_t_mime = mime.
ENDIF.
CREATE OBJECT i_igs_image_converter .
i_igs_image_converter->input = 'image/png'.
i_igs_image_converter->output = 'image/bmp'.
i_igs_image_converter->width = 200.
i_igs_image_converter->height = 200.
CALL METHOD i_igs_image_converter->set_image
EXPORTING
blob = mime
blob_size = l_content_length.
CALL METHOD i_igs_image_converter->execute
EXCEPTIONS
communication_error = 1
internal_error = 2
external_error = 3
OTHERS = 4.
IF sy-subrc = 0.
CALL METHOD i_igs_image_converter->get_image
IMPORTING
blob = blob
blob_size = blob_size
blob_type = blob_type.
ENDIF.
IF sy-subrc = 0.
gi_name = 'QRCODE10'.
gi_object = 'GRAPHICS'.
gi_id = 'BMAP'.
gi_btype = 'BCOL'.
gi_resident = ''.
gi_autoheight = 'X'.
gi_bmcomp = 'X'.
g_extension = 'BMP'.
perform import_bitmap_bds using blob
gi_name
gi_object
gi_id
gi_btype
g_extension
''
gi_resident
gi_autoheight
gi_bmcomp
changing g_docid
gi_resolution.
ENDIF.
Inside Form Routines :
form import_bitmap_bds
using p_blob type w3mimetabtype
p_name type stxbitmaps-tdname
p_object type stxbitmaps-tdobject
p_id type stxbitmaps-tdid
p_btype type stxbitmaps-tdbtype
p_format type c
p_title TYPE bapisignat-prop_value
p_resident type stxbitmaps-resident
p_autoheight type stxbitmaps-autoheight
p_bmcomp type stxbitmaps-bmcomp
changing p_docid type stxbitmaps-docid
p_resolution type stxbitmaps-resolution.
data: l_object_key type sbdst_object_key.
data: l_tab type ddobjname.
data: begin of l_bitmap occurs 0,
l(64) type x,
end of l_bitmap.
data: l_filename type string,
l_bytecount type i,
l_bds_bytecount type i.
data: l_color(1) type c,
l_width_tw type stxbitmaps-widthtw,
l_height_tw type stxbitmaps-heighttw,
l_width_pix type stxbitmaps-widthpix,
l_height_pix type stxbitmaps-heightpix.
data: l_bds_object type ref to cl_bds_document_set,
l_bds_content type sbdst_content,
l_bds_components type sbdst_components,
wa_bds_components type line of sbdst_components,
l_bds_signature type sbdst_signature,
wa_bds_signature type line of sbdst_signature,
l_bds_properties type sbdst_properties,
wa_bds_properties type line of sbdst_properties.
data wa_stxbitmaps type stxbitmaps.
CONSTANTS: c_bds_mimetype type bds_mimetp value 'application/octet-stream',
c_bds_classname type sbdst_classname value 'DEVC_STXD_BITMAP',
c_bds_classtype type sbdst_classtype value 'OT'.
perform enqueue_graphic using p_object
p_name
p_id
p_btype.
call function 'SAPSCRIPT_CONVERT_BITMAP_BDS'
exporting
COLOR = 'X'
format = p_format
RESIDENT = p_resident
bitmap_bytecount = l_bytecount
COMPRESS_BITMAP = p_bmcomp
IMPORTING
WIDTH_TW = l_width_tw
HEIGHT_TW = l_height_tw
WIDTH_PIX = l_width_pix
HEIGHT_PIX = l_height_pix
DPI = p_resolution
BDS_BYTECOUNT = l_bds_bytecount
tables
bitmap_file = p_blob
bitmap_file_bds = l_bds_content
EXCEPTIONS
FORMAT_NOT_SUPPORTED = 1
NO_BMP_FILE = 2
BMPERR_INVALID_FORMAT = 3
BMPERR_NO_COLORTABLE = 4
BMPERR_UNSUP_COMPRESSION = 5
BMPERR_CORRUPT_RLE_DATA = 6
TIFFERR_INVALID_FORMAT = 7
TIFFERR_NO_COLORTABLE = 8
TIFFERR_UNSUP_COMPRESSION = 9
BMPERR_EOF = 10
OTHERS = 11
.
if sy-subrc <> 0.
* Implement suitable error handling here
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
endif.
create object l_bds_object.
wa_bds_components-doc_count = '1'.
wa_bds_components-comp_count = '1'.
wa_bds_components-mimetype = c_bds_mimetype.
wa_bds_components-comp_size = l_bds_bytecount.
append wa_bds_components to l_bds_components.
if p_docid is initial.
wa_bds_signature-doc_count = '1'.
append wa_bds_signature to l_bds_signature.
call method l_bds_object->create_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
components = l_bds_components
content = l_bds_content
changing
signature = l_bds_signature
object_key = l_object_key
exceptions
others = 1.
if sy-subrc <> 0.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
endif.
read table l_bds_signature index 1 into wa_bds_signature
transporting doc_id.
if sy-subrc = 0.
p_docid = wa_bds_signature-doc_id.
else.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
endif.
else.
clear l_object_key.
select single * from stxbitmaps into wa_stxbitmaps
where tdobject = p_object
and tdid = p_id
and tdname = p_name
and tdbtype = p_btype.
select single tabname from bds_locl into l_tab
where classname = c_bds_classname
and classtype = c_bds_classtype.
if sy-subrc = 0.
select single object_key from (l_tab) into l_object_key
where loio_id = wa_stxbitmaps-docid+10(32)
and classname = c_bds_classname
and classtype = c_bds_classtype.
endif.
call method l_bds_object->update_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
object_key = l_object_key
doc_id = p_docid
doc_ver_no = '1'
doc_var_id = '1'
changing
components = l_bds_components
content = l_bds_content
exceptions
nothing_found = 1
others = 2.
if sy-subrc = 1.
wa_bds_signature-doc_count = '1'.
append wa_bds_signature to l_bds_signature.
call method l_bds_object->create_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
components = l_bds_components
content = l_bds_content
changing
signature = l_bds_signature
object_key = l_object_key
exceptions
others = 1.
if sy-subrc <> 0.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
endif.
read table l_bds_signature index 1 into wa_bds_signature
transporting doc_id.
if sy-subrc = 0.
p_docid = wa_bds_signature-doc_id.
else.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
endif.
elseif sy-subrc = 2.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
endif.
endif.
wa_stxbitmaps-tdname = p_name.
wa_stxbitmaps-tdobject = p_object.
wa_stxbitmaps-tdid = p_id.
wa_stxbitmaps-tdbtype = p_btype.
wa_stxbitmaps-docid = p_docid.
wa_stxbitmaps-widthpix = l_width_pix.
wa_stxbitmaps-heightpix = l_height_pix.
wa_stxbitmaps-widthtw = l_width_tw.
wa_stxbitmaps-heighttw = l_height_tw.
wa_stxbitmaps-resolution = p_resolution.
wa_stxbitmaps-resident = p_resident.
wa_stxbitmaps-autoheight = p_autoheight.
wa_stxbitmaps-bmcomp = p_bmcomp.
insert into stxbitmaps values wa_stxbitmaps.
if sy-subrc <> 0.
update stxbitmaps from wa_stxbitmaps.
if sy-subrc <> 0.
endif.
endif.
wa_bds_properties-prop_name = 'DESCRIPTION'.
wa_bds_properties-prop_value = p_title.
append wa_bds_properties to l_bds_properties.
call method l_bds_object->change_properties
exporting
classname = c_bds_classname
classtype = c_bds_classtype
object_key = l_object_key
doc_id = p_docid
doc_ver_no = '1'
doc_var_id = '1'
changing
properties = l_bds_properties
exceptions
others = 1.
perform dequeue_graphic using p_object
p_name
p_id
p_btype.
ENDFORM.
form enqueue_graphic using p_object
p_name
p_id
p_btype.
call function 'ENQUEUE_ESSGRABDS'
EXPORTING
* MODE_STXBITMAPS = 'E'
TDOBJECT = p_object
TDNAME = p_name
TDID = p_id
TDBTYPE = p_btype
* X_TDOBJECT = ' '
* X_TDNAME = ' '
* X_TDID = ' '
* X_TDBTYPE = ' '
* _SCOPE = '2'
* _WAIT = ' '
* _COLLECT = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3 .
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
endform.
form dequeue_graphic using p_object
p_name
p_id
p_btype.
call function 'DEQUEUE_ESSGRABDS'
EXPORTING TDOBJECT = p_object
TDNAME = p_name
TDID = p_id
TDBTYPE = p_btype .
endform.
Below is the code in the report for calling the smartform:
TABLES: anla, anlz.
*
TYPES: BEGIN OF gy_anla,
bukrs TYPE anla-bukrs,
anln1 TYPE anla-anln1,
anln2 TYPE anla-anln2,
aktiv TYPE anla-aktiv,
txt50 TYPE anla-txt50,
END OF gy_anla.
*
TYPES: BEGIN OF gy_anlz,
bukrs TYPE anlz-bukrs,
anln1 TYPE anlz-anln1,
anln2 TYPE anlz-anln2,
bdatu TYPE anlz-bdatu,
kostl TYPE anlz-kostl,
stort TYPE anlz-stort,
END OF gy_anlz.
*
TYPES: BEGIN OF gy_t499s,
werks TYPE t499s-werks,
stand TYPE t499s-stand,
ktext TYPE t499s-ktext,
END OF gy_t499s.
*
DATA: gt_final TYPE STANDARD TABLE OF zrtrs_asset_barcode_label.
*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_bukrs FOR anla-bukrs,
s_anln1 FOR anla-anln1,
s_anln2 FOR anla-anln2,
s_stort FOR anlz-stort.
SELECTION-SCREEN END OF BLOCK b1.
*
AT SELECTION-SCREEN.
*
DATA: l_bukrs TYPE anla-bukrs,
l_anln1 TYPE anla-anln1,
l_stort TYPE anlz-stort.
*
CLEAR: l_bukrs, l_anln1, l_stort.
* Check Company code
SELECT SINGLE bukrs
FROM t093c
INTO l_bukrs
WHERE bukrs IN s_bukrs.
IF sy-subrc IS NOT INITIAL.
MESSAGE 'Company code does not exist'(005) TYPE 'E'
DISPLAY LIKE 'I'.
ENDIF.
* Check Asset code
SELECT SINGLE anln1
FROM anla
INTO l_anln1
WHERE bukrs IN s_bukrs
AND anln1 IN s_anln1
AND anln2 IN s_anln2.
IF sy-subrc IS NOT INITIAL.
MESSAGE 'Asset does not exist'(002) TYPE 'E' DISPLAY LIKE 'I'.
ENDIF.
* Check Location
SELECT SINGLE stand
FROM t499s
INTO l_stort
WHERE stand IN s_stort.
IF sy-subrc IS NOT INITIAL.
MESSAGE 'Location does not exist'(003) TYPE 'E' DISPLAY LIKE 'I'.
ENDIF.
*
START-OF-SELECTION.
*
DATA: lt_anla TYPE STANDARD TABLE OF gy_anla,
lt_anlz TYPE STANDARD TABLE OF gy_anlz,
lt_t499s TYPE STANDARD TABLE OF gy_t499s,
ls_anla TYPE gy_anla,
ls_anlz TYPE gy_anlz,
ls_t499s TYPE gy_t499s,
ls_final TYPE zrtrs_asset_barcode_label.
*
CLEAR: gt_final[], lt_anla[], lt_anlz[], lt_t499s[], ls_anla,
ls_anlz, ls_t499s, ls_final.
* Get Asset
SELECT bukrs anln1
anln2 aktiv txt50
FROM anla
INTO TABLE lt_anla
WHERE bukrs IN s_bukrs
AND anln1 IN s_anln1
AND anln2 IN s_anln2.
IF lt_anla[] IS NOT INITIAL.
* Get location of the Asset
SELECT bukrs anln1
anln2 bdatu
kostl stort
FROM anlz
INTO TABLE lt_anlz
FOR ALL ENTRIES IN lt_anla
WHERE bukrs EQ lt_anla-bukrs
AND anln1 EQ lt_anla-anln1
AND anln2 EQ lt_anla-anln2
AND stort IN s_stort.
IF lt_anlz[] IS NOT INITIAL.
SORT lt_anlz BY bukrs anln1 anln2.
* Get Location description
SELECT werks stand ktext
FROM t499s
INTO TABLE lt_t499s
WHERE stand IN s_stort.
IF sy-subrc IS INITIAL.
SORT lt_t499s BY stand.
ENDIF.
*
LOOP AT lt_anla INTO ls_anla.
ls_final-bukrs = ls_anla-bukrs.
ls_final-anln1 = ls_anla-anln1.
ls_final-anln2 = ls_anla-anln2.
ls_final-aktiv = ls_anla-aktiv.
ls_final-txt50 = ls_anla-txt50.
* Get Asset location
READ TABLE lt_anlz INTO ls_anlz
WITH KEY bukrs = ls_anla-bukrs
anln1 = ls_anla-anln1
anln2 = ls_anla-anln2 BINARY SEARCH.
IF sy-subrc IS INITIAL AND ls_anlz-stort IS NOT INITIAL.
ls_final-bdatu = ls_anlz-bdatu.
ls_final-kostl = ls_anlz-kostl.
ls_final-stort = ls_anlz-stort.
* Get Location description
READ TABLE lt_t499s INTO ls_t499s
WITH KEY stand = ls_anlz-stort BINARY SEARCH.
IF sy-subrc IS INITIAL.
ls_final-werks = ls_t499s-werks.
ls_final-stand = ls_t499s-stand.
ls_final-ktext = ls_t499s-ktext.
ENDIF.
ENDIF.
APPEND ls_final TO gt_final.
CLEAR: ls_anla, ls_anlz, ls_final.
ENDLOOP.
ENDIF.
ENDIF.
*
END-OF-SELECTION.
*
DATA: l_fname TYPE rs38l_fnam,
l_msg TYPE char255.
*
CLEAR: l_fname, l_msg.
*
IF gt_final[] IS NOT INITIAL.
* Get Smartform function module
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZRTRF_PRINT_ASSET_LABEL_COPY'
IMPORTING
fm_name = l_fname
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc IS NOT INITIAL.
* Implement suitable error handling here
ENDIF.
* Print Asset details
call function l_fname
exporting
gt_final = gt_final
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
IF sy-subrc IS NOT INITIAL AND sy-msgid IS NOT INITIAL AND
sy-msgno IS NOT INITIAL.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = sy-msgid
lang = 'E'
no = sy-msgno
v1 = sy-msgv1
v2 = sy-msgv2
v3 = sy-msgv3
v4 = sy-msgv4
IMPORTING
msg = l_msg
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc IS INITIAL.
WRITE l_msg.
ENDIF.
ENDIF.
ELSE.
MESSAGE 'No records were selected'(004) TYPE 'I'.
ENDIF.
On debugging the code, I saw that this particular line is where the dump is being thrown:

On pressing F5,

Can anyone assist me how to rectify this error ?
Regards,
Manish
‎2019 Mar 06 4:52 AM
I have finished the requirement by implementing the note 2340474. I didnt have to write any new logic to obtain the QR code in my smartform, I simple had to call it after testing it for the QR code. Thanks a lot sandra.rossi for your time and assistance.
‎2019 Feb 26 12:28 PM
EDIT March 6th (after the question is closed): so, instead of generating the QR with the Google URL, you simply used the standard QR barcode in SE73 which is supported as of 7.31 (cf note 2029824 - Support for QR code and data matrix bar code). But there is a bug in Basis 7.40 so you had to apply the note 2340474 - SE73: QR code cannot be selected.
Because it's an invalid URL. Copy/paste directly the URL inside your web browser, you'll see... (the "x" is not the well-known roman letter, it's a special symbol which looks like "x")
‎2019 Feb 26 1:21 PM
But how do I get it corrected so that there is no runtime error ? I saw that in the blog, a couple of guys also faced the same issue. But I could not quite follow the solution.
Below is the snapshot :

‎2019 Feb 26 2:14 PM
http_client->receive( EXCEPTIONS http_communication_failure = 1 OTHERS = 2 ).
IF sy-subrc <> 0.
" handle the exception here
ENDIF.
‎2019 Feb 27 5:35 AM
Hi sandra.rossi ,
I am using citrix in my laptop for all client requirements. The funny thing is , when I clicked on the link 'http://chart.apis.google.com/chart?chs=200×200&cht=qr&chld=|1&chl=' from chrome browser outside citrix, I got the qr code image opening up in another webpage as shown:

On the other hand, when I clicked on the link from chrome within citrix, I got the below error:

So maybe, it doesnt have anything to do with the "x" as you mentioned (even though I tried putting "X", "x" and even "*" alongwith the exception that you mentioned in your answer).
Is there any setting that I need to change in my citrix in order to get the image displayed ?
Regards,
Manish
‎2019 Feb 27 7:28 AM
The web page mentions an error in chx=200x200. The same for me. I then retyped the "x" and it worked.
‎2019 Feb 27 1:33 PM
I also retyped it, but It is not working for me. Sy-subrc is coming as 1 , which is the http_communication_failure.
‎2019 Feb 27 1:55 PM
And so, now, do you have the right URL, does it work via your web browser?
‎2019 Feb 28 6:06 AM
Unfortunately no, sandra.rossi . Sy-subrc still gives a value of 1, which is for the http_communication_failure, even though a valid url has been provided.

The url I provided is : https://upload.wikimedia.org/wikipedia/commons/d/d0/QR_code_for_mobile_English_Wikipedia.svg
I am referring to a new link for my requirement, which is: http://letscodeabap.blogspot.com/2015/02/qr-code-in-abap.html
‎2019 Feb 28 7:46 AM
My bad, I didn't pay attention that you could successfully use the URL via your web browser (so I guess you have corrected the "x"-like character which didn't work for me).
So, when you connect to your Citrix server, there's probably a firewall there (chrome within citrix), and another firewall (maybe the same) for the SAP server you access (from the abap program). Ask your administrator for more information.
PS: make sure that at least your server does some simple access with program RSHTTP01 www.google.com (and path empty).
Note that you may also call the method GET_LAST_ERROR to get more information:
if sy-subrc ne 0.
http_client->get_last_error(
importing code = data(subrc)
message = data(errortext) ).
write: / 'code: ', subrc, 'message: ', errortext.
endif.Also, check if there's any short dump with more information (ST22) and check the system log (SM21). You may also start a trace with transaction SMICM.
‎2019 Feb 28 11:19 AM
sandra.rossi The method get_last_error doesnt give me any new information as the method http_receive has a variable called "detail" which is giving me the same information as the variable "error text" inside the former method.


Maybe I have to look for another way to display the qr code as this approach doesnt seem to help me at all. 😞
‎2019 Feb 28 12:31 PM
If you don't ask the administrator, you can't do anything...
But QR is supported in smart forms as of 7.31, no? (cf note 2029824 - Support for QR code and data matrix bar code)
‎2019 Mar 06 4:52 AM
I have finished the requirement by implementing the note 2340474. I didnt have to write any new logic to obtain the QR code in my smartform, I simple had to call it after testing it for the QR code. Thanks a lot sandra.rossi for your time and assistance.