Upload Images in SE78 using SE37 Function Module
FUNCTION zfm_upload_img_se78.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(P_VBELN) TYPE LIKP-VBELN
*"----------------------------------------------------------------------
CONSTANTS:
c_bds_classname TYPE sbdst_classname VALUE 'DEVC_STXD_BITMAP',
c_bds_classtype TYPE sbdst_classtype VALUE 'OT', " others
c_bds_mimetype TYPE bds_mimetp VALUE 'application/octet-stream',
c_bds_original TYPE sbdst_doc_var_tg VALUE 'OR'.
TYPES : BEGIN OF ty_bitmap,
l(64) TYPE x,
END OF ty_bitmap.
DATA: it_dir TYPE TABLE OF epsfili,
wa_dir LIKE LINE OF it_dir,
p_appl TYPE epsdirnam.
DATA : lt_bitmap TYPE STANDARD TABLE OF ty_bitmap,
ls_bitmap TYPE ty_bitmap.
DATA : full_filename TYPE string,
curr_bytes TYPE i,
tot_bytes TYPE i,
l_width_tw TYPE stxbitmaps-widthtw,
l_height_tw TYPE stxbitmaps-heighttw,
l_width_pix TYPE stxbitmaps-widthpix,
l_height_pix TYPE stxbitmaps-heightpix,
p_resolution TYPE stxbitmaps-resolution,
p_resident TYPE stxbitmaps-resident,
p_autoheight TYPE stxbitmaps-autoheight,
p_bmcomp TYPE stxbitmaps-bmcomp,
p_title LIKE bapisignat-prop_value,
l_bds_bytecount TYPE i,
l_bds_content TYPE sbdst_content,
l_bds_object TYPE REF TO cl_bds_document_set,
wa_bds_components TYPE LINE OF sbdst_components,
p_name TYPE stxbitmaps-tdname,
p_object TYPE stxbitmaps-tdobject,
p_id TYPE stxbitmaps-tdid,
p_btype TYPE stxbitmaps-tdbtype,
p_docid TYPE stxbitmaps-docid,
l_bds_components TYPE sbdst_components,
l_bds_signature TYPE sbdst_signature,
wa_bds_signature TYPE LINE OF sbdst_signature,
l_object_key TYPE sbdst_object_key,
wa_stxbitmaps TYPE stxbitmaps,
l_tab TYPE ddobjname,
l_bds_properties TYPE sbdst_properties,
wa_bds_properties TYPE LINE OF sbdst_properties.
p_object = 'GRAPHICS'.
p_id = 'BMAP'.
p_btype = 'BMON'.
" foldernya case sensitif - antara mau buat gede semua atau kecil semua hurufnya
p_appl = '/mnt/fileloc/IMAGES/'.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = p_appl
TABLES
dir_list = it_dir " all the files in the directory
EXCEPTIONS
invalid_eps_subdir = 1
sapgparam_failed = 2
build_directory_failed = 3
no_authorization = 4
read_directory_failed = 5
too_many_read_errors = 6
empty_directory_list = 7
OTHERS = 8.
*BREAK-POINT.
IF sy-subrc = 0.
DATA : lv_name TYPE epsfili-name.
CLEAR lv_name .
CONCATENATE p_vbeln '.bmp' INTO lv_name.
LOOP AT it_dir INTO wa_dir WHERE name = lv_name.
REFRESH : lt_bitmap.
CLEAR : tot_bytes,wa_stxbitmaps.
CONCATENATE p_appl wa_dir-name INTO full_filename.
p_name = wa_dir-name.
TRANSLATE p_name TO UPPER CASE.
* SELECT SINGLE * FROM stxbitmaps INTO wa_stxbitmaps WHERE tdname = p_name.
* IF sy-subrc = 4.
clear : wa_stxbitmaps.
PERFORM enqueue_graphic IN PROGRAM saplstxbitmaps USING p_object
p_name
p_id
p_btype.
OPEN DATASET full_filename FOR INPUT IN BINARY MODE.
WHILE sy-subrc = 0.
CLEAR : curr_bytes, ls_bitmap.
READ DATASET full_filename INTO ls_bitmap ACTUAL LENGTH curr_bytes.
APPEND ls_bitmap TO lt_bitmap.
ADD curr_bytes TO tot_bytes.
ENDWHILE.
CLOSE DATASET full_filename.
* Bitmap conversion
CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP_BDS'
EXPORTING
color = ' '
format = 'BMP'
resident = ''
bitmap_bytecount = wa_dir-size
compress_bitmap = 'X'
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 = lt_bitmap
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
OTHERS = 7.
IF sy-subrc <> 0.
PERFORM dequeue_graphic IN PROGRAM saplstxbitmaps USING p_object
p_name
p_id
p_btype.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
RAISING conversion_failed.
ENDIF.
* Save bitmap in BDS
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. " graphic is new
CLEAR p_docid.
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 IN PROGRAM saplstxbitmaps USING p_object
p_name
p_id
p_btype.
* MESSAGE e285 WITH p_name 'BDS'.
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 IN PROGRAM saplstxbitmaps USING p_object
p_name
p_id
p_btype.
* MESSAGE e285 WITH p_name 'BDS'.
ENDIF.
* ELSE. " graphic already exists
********* read object_key for faster access *****
CLEAR l_object_key.
CLEAR wa_stxbitmaps.
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.
******** read object_key end ********************
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. " inconsistency STXBITMAPS - BDS; repeat check in
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 IN PROGRAM saplstxbitmaps USING p_object
p_name
p_id
p_btype.
* MESSAGE e285 WITH p_name 'BDS'.
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 IN PROGRAM saplstxbitmaps USING p_object
p_name
p_id
p_btype.
* MESSAGE e285 WITH p_name 'BDS'.
ENDIF.
ELSEIF sy-subrc = 2.
PERFORM dequeue_graphic IN PROGRAM saplstxbitmaps USING p_object
p_name
p_id
p_btype.
* MESSAGE e285 WITH p_name 'BDS'.
ENDIF.
* ENDIF.
* Save bitmap header in STXBITPMAPS
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 = 'X'.
wa_stxbitmaps-bmcomp = 'X'.
INSERT INTO stxbitmaps VALUES wa_stxbitmaps.
IF sy-subrc <> 0.
UPDATE stxbitmaps FROM wa_stxbitmaps.
IF sy-subrc <> 0.
* MESSAGE e285 WITH p_name 'STXBITMAPS'.
ENDIF.
ENDIF.
* Set description in BDS attributes
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 IN PROGRAM saplstxbitmaps USING p_object
p_name
p_id
p_btype.
* ENDIF.
ENDLOOP.
ENDIF.
ENDFUNCTION.
0 Response to "SAP ABAP FM UPLOAD IMAGES BMP SHOW AT SE78 "
Post a Comment