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: 

Download attachments from equipments

Former Member
0 Kudos

Hi,

I need to download all the attachments from all the Equipments in our system to a directory structure.

The attachments have been added to the equipment via IE01 / IE02.

For each equipment another directory has to be created.

Someone suggested me to use notes 210802 & 389366 to do this but I have no idea how as I don't know how this is working.

Isn't there an easy way to do this?

For exemple:

Isn't there a way to select all the equipments by reading the table EQUI and to use some functions to get the attachments and to store them localy?

Any help is welcome,

Christophe.

2 REPLIES 2

Former Member
0 Kudos

After looking around I found this:

I can get a list of all attachments from an object using function SREL_GET_NEXT_NEIGHBORS.

Then i use function SO_DOCUMENT_READ_API1 to read the attachment and finaly i use function SO_OBJECT_DOWNLOAD to download it to my windows directory.

The problem i have now is that the files are empty (size 0) OR they are filled but when i open it with the corresponding program ( word, excel, ..) i get an error OR i see empty pages.

To check it out i openend a PDF file with notepad and i can see the pdf code in the file but when i open it i see only an empty page.

Excel and word just give me an error when i open it telling me the file is not correct.

The txt-files are correct if i use file type ASC or DAT but if i use BIN it is empty.

Can someone please give me some advice?

0 Kudos

This is the program i created. I hope someone know what is going wrong.

report zdl_attachments_frm_equipments .

  • Tables ---------------------------------------------------------------

tables: equi.

  • Declarations ---------------------------------------------------------

data: gv_sysid like tbdls-logsys,

gv_lines type i,

gv_str(25) type c,

gv_log(150) type c,

gv_file like rlgrap-filename,

gv_doc_id like sofolenti1-doc_id,

gt_equnrs like equi-equnr occurs 0,

gt_neighbors type standard table of neighbor,

gs_equnrs like line of gt_equnrs,

gs_neighbors like line of gt_neighbors,

gs_equi like equi,

gs_eqkt like eqkt,

gs_equz like equz,

gs_object like borident.

  • Selection screen -----------------------------------------------------

select-options: so_equnr for equi-equnr.

parameters: p_sall as checkbox,

p_test as checkbox.

  • Initialization -------------------------------------------------------

initialization.

p_sall = 'X'.

p_test = 'X'.

  • Start of selection ---------------------------------------------------

start-of-selection.

  • Retrieve system info

call function 'OWN_LOGICAL_SYSTEM_GET'

importing

own_logical_system = gv_sysid

exceptions

own_logical_system_not_defined = 0.

  • Retrieve Equipment numbers

refresh gt_equnrs.

select equnr

into table gt_equnrs

from equi

where equnr in so_equnr.

  • Check if data is found

if sy-subrc ne 0.

write:/1 'No data found for this selection criteria.'.

stop.

endif.

  • Headings

write:/01 'Equipment' color 1,

20 'Technical identification number' color 1,

55 '# Att.' color 1.

  • For all equipments found

loop at gt_equnrs into gs_equnrs.

refresh gt_neighbors.

clear: gs_equi, gs_eqkt, gs_equz, gs_object,

gv_lines, gv_str, gv_log.

write gs_equnrs to gv_log.

  • - Retrieve equipment info

call function 'EQUIPMENT_READ'

exporting

  • I_HANDLE =

  • I_LOCK =

check_auth = 'X'

  • I_TCODE = ' '

equi_no = gs_equnrs

  • EQUZ_NO = '000'

  • READING_DATE = '99991231'

  • X_XAKTYP = ' '

importing

equi = gs_equi

eqkt = gs_eqkt

equz = gs_equz

  • ILOA =

  • EQBS =

  • FLEET =

  • EFHM =

exceptions

auth_no_begrp = 1

auth_no_iwerk = 2

auth_no_swerk = 3

eqkt_not_found = 4

equi_not_found = 5

equz_not_found = 6

iloa_not_found = 7

auth_no_ingrp = 8

auth_no_kostl = 9

err_handle = 10

lock_failure = 11

auth_no_badi = 12

others = 13.

  • - Check if info found

if sy-subrc <> 0.

write 'Error function-call EQUIPMENT_READ' to gv_log+19.

write gv_log color col_negative.

else.

write gs_equz-tidnr to gv_log+19.

gs_object-objkey = gs_equi-equnr.

gs_object-objtype = 'EQUI'.

gs_object-logsys = gv_sysid.

  • - Get list of attachments

call function 'SREL_GET_NEXT_NEIGHBORS'

exporting

object = gs_object

  • ROLETYPE =

  • RELATIONTYPE =

  • MAX_HOPS = 1

tables

neighbors = gt_neighbors

exceptions

internal_error = 1

no_logsys = 2

others = 3.

  • - If attachments found

if sy-subrc eq 0.

describe table gt_neighbors lines gv_lines.

if gv_lines gt 0 or p_sall eq ' '.

write gv_lines to gv_str.

shift gv_str left deleting leading space.

write gv_str to gv_log+54.

write:/ gv_log.

  • - For each attachment

data: gs_doc_data like sofolenti1,

gt_doc_cont type standard table of solisti1.

loop at gt_neighbors into gs_neighbors.

refresh: gt_doc_cont.

clear: gv_doc_id, gs_doc_data, gv_file.

gv_doc_id = gs_neighbors-objkey.

  • - - Get attachment

call function 'SO_DOCUMENT_READ_API1'

exporting

document_id = gv_doc_id

  • FILTER = 'X '

importing

document_data = gs_doc_data

tables

  • OBJECT_HEADER =

object_content = gt_doc_cont

  • OBJECT_PARA =

  • OBJECT_PARB =

  • ATTACHMENT_LIST =

  • RECEIVER_LIST =

exceptions

document_id_not_exist = 1

operation_no_authorization = 2

x_error = 3

others = 4.

if sy-subrc ne 0.

write:/ gs_neighbors-objkey,

':Error in SO_DOCUMENT_READ_API1'.

else.

write:/10 gs_doc_data-object_id, gs_doc_data-obj_type,

gs_doc_data-obj_name, gs_doc_data-obj_descr.

if p_test ne 'X'.

concatenate 'D:\TEMP\' gs_doc_data-object_id '.'

gs_doc_data-obj_type into gv_file.

  • - - Download Attachment

call function 'SO_OBJECT_DOWNLOAD'

exporting

  • BIN_FILESIZE = 0

  • default_filename = ''

filetype = 'DAT'

path_and_file = gv_file

EXTCT = ' '

no_dialog = 'X'

  • IMPORTING

  • FILELENGTH =

  • F_CANCELLED =

  • ACT_FILETYPE =

  • ACT_FILENAME =

tables

objcont = gt_doc_cont

exceptions

file_write_error = 1

invalid_type = 2

x_error = 3

kpro_error = 4

others = 5.

if sy-subrc <> 0.

write:/10 '--> ERROR !!!'.

endif.

endif.

endif.

endloop.

endif.

endif.

endif.

*

endloop.