Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

GUI Container stays alive after all references have been cleared

ventior
Explorer
0 Kudos

I have a problem regarding SAP GUI. I create a QR-Code which I want to display in an HTML-Viewer.

This works until I want to display a different QR-Code afterwards, where I simply load a different bitmap into the html viewer.

For some reason the old HTML-Viewer stays in the Dynpro despite no references to it existing (checked via Debugger) and behaves a little funky. It isn't linked to the typical grid anymore and moves with the scrollbar as seen in the screenshot below.

Does anyone have any idea why I can't kill this thing?

Below is my code (lv_url is where I pass in the URL which is translated into the QR-Code):

DATA: go_qr_code TYPE REF TO cl_gui_html_viewer,
      go_qr_container TYPE REF TO cl_gui_custom_container.
  DATA:errmsg(80)      TYPE c,
ls_bc_cmd TYPE itcoo,
ls_bp_cmd TYPE itcoo,
lv_bitmapsize TYPE i,
lv_bitmap2size TYPE i,
lv_width TYPE i,
lv_height TYPE i,
lt_bitmap TYPE TABLE OF rspolpbi,
lt_bitmap2 TYPE TABLE OF rspolpbi,
ls_bitmap TYPE xstring,
lt_otf TYPE TABLE OF itcoo,
lv_length TYPE i,
lv_hexdata TYPE xstring,
lv_bitmap3 TYPE xstring,
lv_barcode_name TYPE tfo05-tdbarcode VALUE 'ZQRCODE',
lv_url TYPE c LENGTH 1024,
it_html TYPE html_table.
  go_qr_container = NEW cl_gui_custom_container( container_name = 'CCTRL_QR_CODE' ).


PERFORM get_otf_bc_cmd IN PROGRAM sapmssco
USING lv_barcode_name
barcdata
ls_bc_cmd.

IF sy-subrc <> 0.
RETURN.
ENDIF.

ls_bp_cmd-tdprintcom = 'BP'.

PERFORM get_otf_bp_cmd IN PROGRAM sapmssco
USING lv_barcode_name
ls_bp_cmd-tdprintpar.
IF sy-subrc <> 0.
RETURN.
ENDIF.

PERFORM renderbarcode IN PROGRAM sapmssco
TABLES lt_bitmap
USING ls_bc_cmd
ls_bp_cmd
barcdata
lv_bitmapsize
lv_width
lv_height
errmsg.

IF sy-subrc <> 0.
RETURN.
ENDIF.

PERFORM bitmap2otf IN PROGRAM sapmssco
TABLES lt_bitmap
lt_otf
USING lv_bitmapsize
lv_width
lv_height.

FIELD-SYMBOLS <fs> TYPE x.

CLEAR: lv_hexdata, lv_bitmap3.

LOOP AT lt_otf ASSIGNING FIELD-SYMBOL(<ft_otf>).

lv_length = <ft_otf>-tdprintpar+2(2).

ASSIGN <ft_otf>-tdprintpar+4(lv_length) TO <fs> CASTING.

lv_hexdata = <fs>(lv_length).

CONCATENATE lv_bitmap3 lv_hexdata INTO lv_bitmap3 IN BYTE MODE.

ENDLOOP.

* convert from old format to new format

lv_hexdata = 'FFFFFFFF01010000'.

CONCATENATE lv_bitmap3(8) lv_hexdata lv_bitmap3+8 INTO lv_bitmap3 IN BYTE MODE.

CLEAR lv_hexdata.

SHIFT lv_hexdata RIGHT BY 90 PLACES IN BYTE MODE.

CONCATENATE lv_bitmap3(42) lv_hexdata lv_bitmap3+42 INTO lv_bitmap3 IN BYTE MODE.

DATA bitmap4 TYPE sbdst_content.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_bitmap3 " xstring
TABLES
binary_tab = bitmap4.

DATA bitmap4_size TYPE i.

bitmap4_size = xstrlen( lv_bitmap3 ).

CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'
EXPORTING
old_format = 'BDS'
new_format = 'BMP'
bitmap_file_bytecount_in = bitmap4_size
IMPORTING
bitmap_file_bytecount = lv_bitmap2size
TABLES
bitmap_file = lt_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 FUNCTION 'DP_CREATE_URL'
EXPORTING
type = 'IMAGE' " MIME-Type
subtype = 'BMP' " MIME-SubType
TABLES
data = lt_bitmap2 " Tabelle, die die Daten des URL enthält.
CHANGING
url = lv_url " Temprärer URL
EXCEPTIONS
dp_invalid_parameter = 1 " Ungültiger Parameter
dp_error_put_table = 2 " Tabelle konnte nicht übertragen werden
dp_error_general = 3 " Allgemeiner Fehler
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

go_qr_code = NEW cl_gui_html_viewer( parent = go_qr_container ).

it_html = VALUE html_table( ( |<html>| )
( | <head>| )
( | <title>QR_CODE</title>| )
( | </head>| )
( | <body>| )
( | <img src="{ lv_url }" style="display: block; width: 95%">| )
( | | )
( | </body>| )
( |</html>| ) ).

go_qr_code->load_data( IMPORTING
assigned_url = lv_url
CHANGING
data_table = it_html ).
go_qr_code->show_url( url = lv_url ).



cl_gui_cfw=>flush( ).
1 ACCEPTED SOLUTION

ventior
Explorer

Thanks to sandra.rossi in the comments, this issue was fixed by adding the free method to both, the container and the html viewer.

3 REPLIES 3

Sandra_Rossi
Active Contributor

Classic issue. I don't see the method go_qr_code->FREE or go_qr_container->FREE in your code...

ventior
Explorer
0 Kudos

sandra.rossi Thank you! The thing is I already tried using free on both my container and my QR-Code but I must have messed it up somewhere - since I still had that issue.

Anyways, it's fixed now.

ventior
Explorer

Thanks to sandra.rossi in the comments, this issue was fixed by adding the free method to both, the container and the html viewer.