Este es otro caso,
en ocasiones a alguien se le ocurre bajar todas las imágenes del personal que
están cargadas en SAP. Si bien hay varias formas, en este caso se pide que sean
almacenadas en una carpeta local ó de red, en donde la imagen tenga el número
de personal como nombre.
Bueno yo sin hacerme
mucho problema modifique un ejemplo que está en internet para este proceso.
En este ejemplo se
utilizan las funciones: HR_IMAGE_EXISTS y SCMS_DOC_READ_FILES. Donde la última
tiene algunas particularidades que he resuelto de forma bien practica. Y como
siempre digo si hay una forma mejor y más fácil me cuentan.
Programa principal.
data : vg_pernr(8) type c.
data: error type sysubrc,
descr type char100.
…
parameters: p_file like rlgrap-filename obligatory.
…
get pernr.
vg_pernr = pernr-pernr.
concatenate p_file '\' vg_pernr '.jpg' into vg_destino.
condense vg_destino.
perform download_foto using pernr-pernr sy-datum sy-datum
vg_destino error descr.
…
form download_foto using p_pernr type pernr-pernr
p_begda type prelp-begda
p_endda type prelp-endda
p_path type c
error type sysubrc
descr type char100.
data: l_exists type c,
l_connect_info type toav0.
*
call function 'HR_IMAGE_EXISTS'
exporting
p_pernr = p_pernr
p_tclas = 'A'
p_begda = p_begda
p_endda = p_endda
importing
p_exists = l_exists
p_connect_info = l_connect_info
exceptions
error_connectiontable = 1
others = 2.
if ( sy-subrc = 0 ).
* llama a programa dummy para DL de Foto
submit zhcm_sql_fotos_dl
using selection-sets of program 'ZHCM_SQL_FOTOS_DL'
with a_id eq l_connect_info-archiv_id
with a_doc eq l_connect_info-arc_doc_id
with path eq p_path
exporting list to memory
and return.
import error descr from memory id 'Photos'.
free memory id 'Photos'.
else.
error = sy-subrc.
case error.
when 1.
descr = '(HR_IMAGE_EXISTS) Error_connectiontable'.
when others.
descr = '(HR_IMAGE_EXISTS) Others'.
endcase.
endif.
endform. "Download_foto
*&---------------------------------------------------------------------*
Programa dummy para encarpsulamiento (evitar el error por las 26
ejecuciones)
*&---------------------------------------------------------------------*
report zhcm_sql_fotos_dl.
parameters: a_id type toav0-archiv_id,
a_doc type toav0-arc_doc_id,
path type char255.
data: error type sysubrc,
decri type char100.
call function 'ZHCM_PHOTOS_DOWNLOAD'
exporting
p_id = a_id
p_doc = a_doc
p_path = path
importing
error = error
descripcion = decri.
export error decri to memory id 'Photos'.
*&---------------------------------------------------------------------*
RFC
function zhcm_photos_download.
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" REFERENCE(P_ID) LIKE TOAV0-ARCHIV_ID
*" REFERENCE(P_DOC) LIKE TOAV0-ARC_DOC_ID
*" REFERENCE(P_PATH) TYPE CHAR255
*" EXPORTING
*" VALUE(ERROR) TYPE SYSUBRC
*" VALUE(DESCRIPCION) TYPE CHAR100
*"----------------------------------------------------------------------
data: dym type table of rssource-line,
code type table of rssource-line,
line type edpline,
prog(8) type c,
msg(120) type c,
lin(3) type c,
wrd(10) type c,
off(3) type c.
data: linea type edpline.
append 'PROGRAM ZEXECUTE_DOWNLOAD_PHOTO.' to code.
append 'FORM execute USING error.' to code.
append 'DATA: ' to code.
clear linea.
concatenate' l_comps TYPE STANDARD TABLE OF scms_doinf '
' WITH HEADER LINE. ' into linea .
append linea to code.
*
append ' CALL FUNCTION ' to code.
concatenate '''' 'SCMS_DOC_READ_FILES' ''''
into linea in character mode." RESPECTING BLANKS.
append linea to code.
append ' EXPORTING ' to code.
append ' mandt = sy-mandt ' to code.
append ' stor_cat = space ' to code.
clear linea.
concatenate' crep_id = ' '''' p_id '''' into linea.
append linea to code.
clear linea.
concatenate' doc_id = ' '''' p_doc '''' into linea.
append linea to code.
clear linea.
concatenate' path = ' '''' p_path '''' into linea.
append linea to code.
clear linea.
concatenate ' frontend = ' '''' 'X' '''' into linea.
append linea to code.
append ' tables ' to code.
append ' comps = l_comps ' to code.
append ' exceptions ' to code.
append ' bad_storage_type = 1 ' to code.
append ' bad_request = 2 ' to code.
append ' unauthorized = 3 ' to code.
append ' not_found = 4 ' to code.
append ' conflict = 5 ' to code.
append ' internal_server_error = 6 ' to code.
append ' error_http = 7 ' to code.
append ' error_signature = 8 ' to code.
append ' error_config = 9 ' to code.
append ' error_hierarchy = 10 ' to code.
append ' error_download = 11 ' to code.
append ' error_open = 12 ' to code.
append ' error_parameter = 13 ' to code.
append ' error = 14 ' to code.
append ' others = 15. ' to code.
append ' if sy-subrc <> 0. ' to code.
append ' error = sy-subrc. ' to code.
append ' endif. ' to code.
append ' ENDFORM. ' to code.
*
generate subroutine pool code name prog
message msg
line lin
word wrd
offset off.
if sy-subrc ne 0.
* raise error_formula.
else.
try.
perform execute in program (prog)
using error.
case error.
when 1.
descripcion = '(SCMS_DOC_READ_FILES)bad_storage_type'.
when 2.
descripcion = '(SCMS_DOC_READ_FILES)bad_request'.
when 3.
descripcion = '(SCMS_DOC_READ_FILES)unauthorized'.
when 4.
descripcion = '(SCMS_DOC_READ_FILES)not_found'.
when 5.
descripcion = '(SCMS_DOC_READ_FILES)conflict'.
when 6.
descripcion = '(SCMS_DOC_READ_FILES)internal_server_error'.
when 7.
descripcion = '(SCMS_DOC_READ_FILES)error_http'.
when 8.
descripcion = '(SCMS_DOC_READ_FILES)error_signature'.
when 9.
descripcion = '(SCMS_DOC_READ_FILES)error_config'.
when 10.
descripcion = '(SCMS_DOC_READ_FILES)error_hierarchy'.
when 11.
descripcion = '(SCMS_DOC_READ_FILES)error_download'.
when 12.
descripcion = '(SCMS_DOC_READ_FILES)error_open'.
when 13.
descripcion = '(SCMS_DOC_READ_FILES)error_parameter'.
when 14.
descripcion = '(SCMS_DOC_READ_FILES)error'.
when others.
descripcion = '(SCMS_DOC_READ_FILES)others'.
endcase.
endtry.
endif.
endfunction.
*&---------------------------------------------------------------------*