Ver Mensaje Individual
  #6  
Viejo 06/06/13, 15:14:02
abfv abfv is offline
Senior Member
 
Fecha de Ingreso: feb 2008
Localización: Buenos Aires - Argentina
Mensajes: 144
Cool Foto en smartform

Hola, te paso una descripción de cada rutina y los porque, está para unix y puede ser que vos tengas otro S.O. en ese caso cambiá una función y listo.

Priemero la FOTO a la SE78 para poder obtener la imagen desde allí

FORM FOTO_A_SE78 .

*data: p_file type localfile value 'C:file.bmp'.
data: p_file type localfile.
data: p_image type stxbitmaps-tdname.
data: imagename type stxbitmaps-tdname.
data: w_emple(8) TYPE n.

* Coloco ruta al nombre del empleado
WRITE t_pernr-pernr TO w_imagen NO-ZERO.
CONDENSE w_imagen NO-GAPS.
WRITE t_pernr-pernr TO w_emple.

concatenate '/carpeta/Img_' w_emple '.bmp' INTO p_file.

* Nombre de la imagen el la SE78
* imagename = 'FOTOEMPLE'.
imagename = sy-uname. "aca ponemos el n° de personal ya que luego lo paso como parámetro al smartform para buscar la foto


perform import_bitmap using p_file
imagename
'Test Image'.

ENDFORM. "FOTO_A_S



form import_bitmap using filename
name
title.

data: l_resolution type stxbitmaps-resolution.
data: l_docid type stxbitmaps-docid.

perform import_bitmap_bds
using filename
name
'GRAPHICS' "Object
'BMAP' "ID
'BCOL' "B/W
'BMP' "Extension
title
''
'X'
''
changing l_docid
l_resolution.


ENDFORM. "import_bitmap




form import_bitmap_bds
using p_filename type rlgrap-filename
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 like 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 bapibds01-objkey.
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.

* Graphic handling
constants:
c_stdtext like thead-tdobject value 'TEXT',
c_graphics like thead-tdobject value 'GRAPHICS',
c_bmon like thead-tdid value 'BMON',
c_bcol like thead-tdid value 'BCOL'.

constants:
c_true type c value 'X',
c_false type c value space.

types:
ty_boolean(1) type c.

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'.


* Enqueue
perform enqueue_graphic
in program saplstxbitmaps
using p_object
p_name
p_id
p_btype.

* Paso la foto a Binario
l_filename = p_filename.
OPEN DATASET l_filename FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
DO.
READ DATASET l_filename INTO l_bitmap.
APPEND l_bitmap.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET l_filename.
ELSE.
w_sinfoto = 'X'.
EXIT.

ENDIF.

l_bytecount = sy-tabix - 1.

* Las siguientes filas comentadas son para pasar a binario
* un archivo en disco local a través de una función.

* File transfer
*********** l_filename = p_filename.
*********** call function 'GUI_UPLOAD'
*********** exporting
*********** filename = l_filename
*********** filetype = 'BIN'
*********** importing
*********** filelength = l_bytecount
*********** tables
*********** data_tab = l_bitmap
*********** exceptions
*********** file_open_error = 2
*********** file_read_error = 3
*********** no_batch = 1
*********** 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.
*********** case sy-subrc.
*********** when 0.
*********** when 2. perform dequeue_graphic
*********** in program saplstxbitmaps
*********** using p_object
*********** p_name
*********** p_id
*********** p_btype.
************ message e811 with p_filename.
*********** when 3. perform dequeue_graphic
*********** in program saplstxbitmaps
*********** using p_object
*********** p_name
*********** p_id
*********** p_btype.
************ message e812 with p_filename.
*********** when others. perform dequeue_graphic
*********** in program saplstxbitmaps
*********** using p_object
*********** p_name
*********** p_id
*********** p_btype.
************ message e813 with p_filename.
*********** endcase.
* Fin de comentario para pasar a binario por función


if p_btype = c_bmon.
l_color = c_false.
else.
l_color = c_true.
endif.

* Bitmap conversion
call function 'SAPSCRIPT_CONVERT_BITMAP_BDS'
EXPORTING
color = l_color
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 = l_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

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.
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 = 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.
* 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.


ENDFORM.


Luego de todo esto en el smartform creas un objeto imagen y en nombre le colocas la variable que tiene el N° de personal. Ej. &P_IMAGEN&

Espero sea de ayuda.

Saludos.
Responder Con Cita