Skip to Content
0
Jun 05 at 06:34 AM

SAPGUI crash while printing employee photo on smartform

84 Views Last edit Jun 06 at 04:37 AM 3 rev

Custom program is developed which prints employee photo using smartform.

Employee photo is uploaded in OAAD transaction, to print that photo on smartform image is converted to bitmap and uploaded in SE78 tcode.

When this converted photo is printed on smartform SAP GUI gets crash.

error.jpg

Below Code:

CONCATENATE 'C:\TEMP\' pernr '.jpg' INTO zfilename.

"0. Check image on SE78 if exist delete
SELECT SINGLE * FROM stxbitmaps INTO wa_stxbitmaps
WHERE tdobject = 'GRAPHICS'
AND tdname = pernr
AND tdid = 'BMAP'
AND tdbtype = 'BCOL'.
IF sy-subrc EQ 0.
DELETE stxbitmaps FROM wa_stxbitmaps.
ENDIF.

"1. Check Photo
CALL FUNCTION 'HR_IMAGE_EXISTS'
EXPORTING
p_pernr = pernr
p_tclas = 'A'
p_begda = sy-datum
p_endda = sy-datum
IMPORTING
p_exists = p_exists
p_connect_info = p_connect_info
EXCEPTIONS
error_connectiontable = 1
OTHERS = 2.
IF sy-subrc <> 0.
"Create photo not avaiableSELECT SINGLE * FROM stxbitmaps INTO wa_stxbitmaps
SELECT SINGLE * FROM stxbitmaps INTO wa_stxbitmaps
WHERE tdobject = 'GRAPHICS'
AND tdname = 'NOPHOTO'
AND tdid = 'BMAP'
AND tdbtype = 'BCOL'.
IF sy-subrc EQ 0.
wa_stxbitmaps-tdname = pernr.
INSERT INTO stxbitmaps VALUES wa_stxbitmaps.
ELSE.
SELECT SINGLE * FROM stxbitmaps INTO wa_stxbitmaps
WHERE tdobject = 'GRAPHICS'
AND tdname = 'ENJOY'
AND tdid = 'BMAP'
AND tdbtype = 'BCOL'.
wa_stxbitmaps-tdname = pernr.
INSERT INTO stxbitmaps VALUES wa_stxbitmaps.
ENDIF.
ENDIF.
"Check photo exist
CHECK p_exists EQ 1.

"2. Now Read the image in JPG format by using below function module.
CALL FUNCTION 'ALINK_RFC_TABLE_GET'
EXPORTING
im_docid = p_connect_info-arc_doc_id
im_crepid = p_connect_info-archiv_id
IMPORTING
ex_length = length
TABLES
ex_document = it_doc.

"3. Convert the image from JPG Format to Binary Format by using the below function module.
crep_id = p_connect_info-archiv_id.
doc_id = p_connect_info-arc_doc_id.
phio_id = p_connect_info-object_id.

CALL FUNCTION 'SCMS_R3DB_IMPORT'
EXPORTING
mandt = sy-mandt
crep_id = crep_id
doc_id = doc_id
phio_id = phio_id
TABLES
content_bin = it_bin
EXCEPTIONS
error_import = 1
error_config = 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.
* ENDIF.

"4. create a folder in the presentation layer in one of the directory. By using below function module.
CALL FUNCTION 'TMP_GUI_CREATE_DIRECTORY'
EXPORTING
dirname = 'C:\TEMP'
no_flush = ' '
EXCEPTIONS
failed = 1
OTHERS = 2.
* IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* ENDIF.

"5. download the image of the pernr into this folder by using below function module.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = zfilename
filetype = 'BIN'
TABLES
data_tab = it_bin
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
* IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* ENDIF.

* BREAK-POINT.

"6. Now upload the file which you have downloaded by using the function module.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = zfilename
filetype = 'BIN'
IMPORTING
filelength = l_content_length
TABLES
data_tab = mime
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
* IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* ENDIF.

* BREAK-POINT.

"7. convert the binary to bitmap using the below code.
CREATE OBJECT i_igs_image_converter .
i_igs_image_converter->input = 'image/jpeg'.
i_igs_image_converter->output = 'image/x-ms-bmp'.
i_igs_image_converter->width = '100'.
i_igs_image_converter->height = '100'.

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.
dpi = '100'.
CALL METHOD i_igs_image_converter->get_image
IMPORTING
blob = blob
blob_size = blob_size
blob_type = blob_type.
ENDIF.

"8. Convert Bitmap to BDS by using the function module.
CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP_BDS'
EXPORTING
color = 'X'
format = 'BMP'
bitmap_bytecount = length
IMPORTING
width_tw = l_width_tw
height_tw = l_height_tw
width_pix = l_width_pix
height_pix = l_height_pix
dpi = dpi
TABLES
bitmap_file = 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.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* ENDIF.

* BREAK-POINT.

"9. upload the Picture in SE78 by using the below code:
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 = blob_size. "l_bds_bytecount.
APPEND wa_bds_components TO l_bds_components.
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.
READ TABLE l_bds_signature INDEX 1 INTO wa_bds_signature
TRANSPORTING doc_id.
p_docid = wa_bds_signature-doc_id.
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.

wa_stxbitmaps-tdname = pernr.
wa_stxbitmaps-tdobject = 'GRAPHICS'.
wa_stxbitmaps-tdid = 'BMAP'.
wa_stxbitmaps-tdbtype = 'BCOL'.
wa_stxbitmaps-docid = p_docid.
wa_stxbitmaps-widthpix = l_width_pix. "'450'. "'540'.”'640' .”l_width_pix.
wa_stxbitmaps-heightpix = l_height_pix. "'400'. "'480'. "l_height_pix.
wa_stxbitmaps-widthtw = l_width_tw. "'11200'. "'12288'.”l_width_tw.
wa_stxbitmaps-heighttw = l_height_tw. "'8000'. "'9216'.”l_height_tw.
wa_stxbitmaps-resolution = '100'.
INSERT INTO stxbitmaps VALUES wa_stxbitmaps.

"10. delete the file which is present on presentation layer by using below FM.
CALL METHOD cl_gui_frontend_services=>file_delete
EXPORTING
filename = zfilename
CHANGING
rc = rc
EXCEPTIONS
file_delete_failed = 1
cntl_error = 2
error_no_gui = 3
file_not_found = 4
access_denied = 5
unknown_error = 6
not_supported_by_gui = 7
wrong_parameter = 8
OTHERS = 9.
* IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* ENDIF.

"11. After all the employees delete the floder in the presentation layer which you have created.
"Note: Give the name of the Picture when your are uploading into SE78 as Employee Number so that for every employee we will get pictures individually in SE78 as name as Employee Number.
"Now in order to print Employee Photo dynamically in smart forms. Generally we use graphic window for displaying Logos, Photos etc.
"But here we have to print Employee Photo for particular employee. So in order to do this code as shown below .This code we have to create program lines then we need to write below code before graphic node.

"DATA: wa_stxbitmaps TYPE stxbitmaps.
CLEAR:wa_stxbitmaps.
wa_stxbitmaps-tdname = pernr.
wa_stxbitmaps-tdobject = 'GRAPHICS'.
wa_stxbitmaps-tdid = 'BMAP'.
wa_stxbitmaps-tdbtype = 'BCOL'.

CALL FUNCTION 'SSFCOMP_PRINT_GRAPHIC'
EXPORTING
bm_name = wa_stxbitmaps-tdname
bm_object = wa_stxbitmaps-tdobject
bm_id = wa_stxbitmaps-tdid
bm_type = wa_stxbitmaps-tdbtype
bm_dpi = '0100'
EXCEPTIONS
error = 1
non_main_overflow = 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.
ENDIF.

CLEAR: length,crep_id,doc_id,phio_id,l_content_length,
l_bds_signature,l_object_key,wa_bds_signature,
wa_bds_components,wa_stxbitmaps.
REFRESH: it_doc,it_bin,mime,blob,l_bds_content.
FREE i_igs_image_converter.
FREE l_bds_object.

Attachments

error.jpg (107.6 kB)