100% found this document useful (1 vote)
689 views9 pages

1333 Downloading Attachments of Services For Objects

This program enables downloading attachments from SAP in binary format. It retrieves attachment information from table SRGBTBREL. For each attachment found, it downloads the binary file to the specified file path. Any errors encountered are written out.

Uploaded by

Zvika Lerer
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
689 views9 pages

1333 Downloading Attachments of Services For Objects

This program enables downloading attachments from SAP in binary format. It retrieves attachment information from table SRGBTBREL. For each attachment found, it downloads the binary file to the specified file path. Any errors encountered are written out.

Uploaded by

Zvika Lerer
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Downloading attachments of services for objects

Written by Ctac Ben Meijs


Wednesday, 22 July 2009 15:13 -

This program enables you to download attachments in BINARY format to your client. These
attachments are for example attached using the object services option. In table SRGBTBREL,
the information is stored that is needed to find attachments.

* &---------------------------------------------------------------------*
* & C T A C T E M P L A T E S A N D T O O L S
* &---------------------------------------------------------------------*
* & Author | Ctac Ben Meijs
* & Date | Oktober 2006
* & Release | R/3 6.20 vv
* & Version | V1
* & Released for use | 12-10-2006
* &---------------------------------------------------------------------*
* $ Purpose | Download Tool for attachments
* &---------------------------------------------------------------------*
* $*$----------------------------------------------------------------*
* $*$ Company : Ctac AMI
* $*$ Author : Ben Meijs
* $*$ Date : 12-10-2006
* $*$ SAP rel. : 620 vv
* $*$ Transport:
*
* This program enables you to download attachments in BINARY format
* to your client. These attachments are for example attached using
* the object services option.
* In table SRGBTBREL, the information is stored that is needed
* to find attachments.
*
* No updates are performed in this program.
* $*$----------------------------------------------------------------*
* $*$----------------------------------------------------------------*
* $*$ M O D I F I C A T I O N S *
* $*$----------------------------------------------------------------*
* & Author |
* & Date | ..-..-....
* & Change | Notification/Project - Customernumber
* & Transport request|
* & Purpose Change |
* & |
* & DB-Changes | (database updates?, relatie tussen updates)
* &-------------------------------------------------------------------*

1/9

Downloading attachments of services for objects


Written by Ctac Ben Meijs
Wednesday, 22 July 2009 15:13 -

* $*$----------------------------------------------------------------*
* $*$ G L O B A L T Y P E D E C L A R A T I O N *
* $*$----------------------------------------------------------------*
* $*$----------------------------------------------------------------*
* $*$ Type pool declarations
* $*$----------------------------------------------------------------*
TYPE-POOLS: abap, "ABAP reporting types / constants
icon. "Possible icons
* $*$----------------------------------------------------------------*
* $*$ Type Definitions
* $*$----------------------------------------------------------------*
TYPES: ty_fieldname(80) TYPE c. TYPES:
BEGIN OF ts_key,
foltp TYPE so_fol_tp,
folyr TYPE so_fol_yr,
folno TYPE so_fol_no,
objtp TYPE so_obj_tp,
objyr TYPE so_obj_yr,
objno TYPE so_obj_no,
forwarder TYPE so_usr_nam,
END OF ts_key .
TYPES:
BEGIN OF ts_attachment,
foltp TYPE so_fol_tp,
folyr TYPE so_fol_yr,
folno TYPE so_fol_no,
objtp TYPE so_obj_tp,
objyr TYPE so_obj_yr,
objno TYPE so_obj_no,
brelguid TYPE oblguid32,
roletype TYPE oblroltype,
END OF ts_attachment .
TYPES:
tt_attachment TYPE TABLE OF ts_attachment .
* $*$----------------------------------------------------------------*

2/9

Downloading attachments of services for objects


Written by Ctac Ben Meijs
Wednesday, 22 July 2009 15:13 -

* $*$ G L O B A L D A T A D E C L A R A T I O N *
* $*$----------------------------------------------------------------*
* $*$----------------------------------------------------------------*
* $*$ Global Data Declarations
* $*$----------------------------------------------------------------*
TABLES: soc3. "contains
DATA: ta_srgbtbrel TYPE STANDARD TABLE OF srgbtbrel,
wa_srgbtbrel TYPE srgbtbrel,
wa_sood TYPE sood.
DATA:
tp_path TYPE ty_fieldname VALUE 'FILENAME-FILEEXTERN'.
* $*$----------------------------------------------------------------*
* $*$ S E L E C T I O N S C R E E N *
* $*$----------------------------------------------------------------*
* $*$ Define your selection-criteria here *
* $*$----------------------------------------------------------------*
SELECT-OPTIONS: so_insti FOR wa_srgbtbrel-instid_a,
so_typid FOR wa_srgbtbrel-typeid_a DEFAULT 'TRDIR',
so_catid FOR wa_srgbtbrel-catid_a DEFAULT 'BO'.
PARAMETERS : pa_filty(3) TYPE c DEFAULT 'BIN' OBLIGATORY,
pa_path LIKE (tp_path) OBLIGATORY.
* $*$-------------------------------------------------------------------*
* $*$ M A I N P R O C E S S I N G *
* $*$-------------------------------------------------------------------*
START-OF-SELECTION.
SELECT * FROM srgbtbrel INTO TABLE ta_srgbtbrel
WHERE instid_a IN so_insti
AND typeid_a IN so_typid
AND catid_a IN so_catid.
IF sy-subrc eq 0.
SORT ta_srgbtbrel BY instid_a typeid_a catid_a.

3/9

Downloading attachments of services for objects


Written by Ctac Ben Meijs
Wednesday, 22 July 2009 15:13 -

DELETE ADJACENT DUPLICATES FROM ta_srgbtbrel


COMPARING instid_a typeid_a catid_a.
LOOP AT ta_srgbtbrel INTO wa_srgbtbrel.
PERFORM process_attachments
USING wa_srgbtbrel-instid_a
wa_srgbtbrel-typeid_a
wa_srgbtbrel-catid_a.
ENDLOOP.
ENDIF.
END-OF-SELECTION.
*
* $*$-------------------------------------------------------------------*
* $*$ F O R M R O U T I N E S *
* $*$-------------------------------------------------------------------*
* &---------------------------------------------------------------------*
* & Form process_attachments
* &---------------------------------------------------------------------*
* Process attachemnts for one specific object
* ----------------------------------------------------------------------*
FORM process_attachments USING
utp_instid TYPE any
utp_typeid TYPE c
utp_catid TYPE c.
DATA: lta_sood TYPE STANDARD TABLE OF sood,
lwa_sood TYPE sood.
DATA: ltp_pathin(1000) type c,
ltp_filename TYPE string.
DATA: ltp_sortfield TYPE char30.
DATA: lta_objcont TYPE soli_tab.
DATA: ltp_binfilesize LIKE soxwd-doc_length.
DATA: lta_attachments TYPE tt_attachment,
lwa_attachments LIKE LINE OF lta_attachments.
* 1 First get all attachment to find the link that
PERFORM get_item_links
USING utp_instid

4/9

Downloading attachments of services for objects


Written by Ctac Ben Meijs
Wednesday, 22 July 2009 15:13 -

utp_typeid
utp_catid
CHANGING
lta_attachments.
CHECK LINES( lta_attachments ) > 0.
LOOP AT lta_attachments INTO lwa_attachments.
WRITE: / utp_instid,
utp_typeid,
utp_catid .
CLEAR lta_sood[].
SELECT * FROM sood INTO TABLE lta_sood
WHERE
objtp = lwa_attachments-objtp AND
objyr = lwa_attachments-objyr AND
objno = lwa_attachments-objno.
* For every attachment! (probably one-on-one)
LOOP AT lta_sood INTO lwa_sood.
ltp_pathin = pa_path.
ltp_binfilesize = wa_sood-objlen.
WRITE: lwa_sood-objtp,
lwa_sood-objyr,
lwa_sood-objno.
CONCATENATE
lwa_sood-objtp
lwa_sood-objyr
lwa_sood-objno
INTO ltp_sortfield.
IMPORT
* objhead_tab
objcont_tab TO lta_objcont
* objpara_tab
* objparb_tab
* transa
* report

5/9

Downloading attachments of services for objects


Written by Ctac Ben Meijs
Wednesday, 22 July 2009 15:13 -

* dialog
* functi
FROM DATABASE soc3(dt) ID ltp_sortfield.
IF sy-subrc = 0.
* Create name of the attachment
CONCATENATE
ltp_pathin
''
utp_typeid '_'
utp_instid '_'
lwa_sood-objdes
'.'
lwa_sood-file_ext
INTO ltp_pathin.
* make sure that in the path to client, no double slashes are
* entered (except first two positions)
REPLACE '\' WITH '' INTO ltp_pathin+2.
TRANSLATE ltp_pathin USING '/ '.
* Download to the
CALL FUNCTION 'SO_OBJECT_DOWNLOAD'
EXPORTING
bin_filesize = ltp_binfilesize
default_filename =
filetype = pa_filty
path_and_file = ltp_pathin
extct = lwa_sood-extct
no_dialog = 'X'
* codepage =
IMPORTING
* FILELENGTH =
* F_CANCELLED =
* ACT_FILETYPE =
act_filename = ltp_filename
TABLES

6/9

Downloading attachments of services for objects


Written by Ctac Ben Meijs
Wednesday, 22 July 2009 15:13 -

objcont = lta_objcont
EXCEPTIONS
file_write_error = 1
invalid_type = 2
x_error = 3
kpro_error = 4
OTHERS = 5
.
IF sy-subrc <> 0.
WRITE: 'Error Download'(e02),
sy-msgid ,
sy-msgty,
sy-msgno,
sy-msgv1, sy-msgv2, sy-msgv3, sy-msgv4.
ELSE.
WRITE: 'OK download'(e01), ltp_filename.
ENDIF.
ELSE.
WRITE: 'Error download'(e02), ltp_sortfield.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDFORM. "process_attachments
* &---------------------------------------------------------------------*
* & Form get_item_links
* &---------------------------------------------------------------------*
* This form is copied from a SAP method used by object services
* to find all links for one object
* The three formal parameters of this routine identify the object.
* Every object can have more than one attachment.
* &---------------------------------------------------------------------*
FORM get_item_links USING utp_instid TYPE any
utp_typeid TYPE c
utp_catid TYPE c
CHANGING
cta_attachments TYPE tt_attachment.
* Data definitions from SAP are taken over without changing naming
* conventions

7/9

Downloading attachments of services for objects


Written by Ctac Ben Meijs
Wednesday, 22 July 2009 15:13 -

DATA:
lo_boritem TYPE REF TO cl_sobl_bor_item,
lo_al_item TYPE REF TO cl_gos_al_item,
li_link TYPE REF TO if_browser_link,
ls_option TYPE obl_s_relt,
lt_options TYPE obl_t_relt,
ls_key TYPE ts_key,
ls_attachment TYPE ts_attachment,
lt_attachment TYPE tt_attachment,
lt_links TYPE obl_t_link,
ls_link TYPE obl_s_link,
lp_linkid TYPE blnk_inst.
DATA: gs_lpor TYPE sibflporb.
* go_bitem = io_bitem.
CLEAR cta_attachments[].
gs_lpor-instid = utp_instid.
gs_lpor-typeid = utp_typeid.
gs_lpor-catid = utp_catid.
ls_option-sign = 'I'.
ls_option-option = 'EQ'.
ls_option-low = 'ATTA'.
APPEND ls_option TO lt_options.
ls_option-low = 'NOTE'.
APPEND ls_option TO lt_options.
ls_option-low = 'URL'.
APPEND ls_option TO lt_options.
TRY.
CALL METHOD cl_binary_relation=>read_links_of_binrels
EXPORTING
is_object = gs_lpor
it_relation_options = lt_options
ip_role = 'GOSAPPLOBJ'
ip_no_buffer =
IMPORTING
et_links = lt_links.
.
LOOP AT lt_links INTO ls_link.

8/9

Downloading attachments of services for objects


Written by Ctac Ben Meijs
Wednesday, 22 July 2009 15:13 -

CASE ls_link-typeid_b .
WHEN 'MESSAGE'.
ls_key = ls_link-instid_b.
MOVE-CORRESPONDING ls_key TO ls_attachment.
ls_attachment-roletype = ls_link-roletype_b.
IF ls_link-brelguid IS INITIAL.
ls_attachment-brelguid = ls_link-relguidold.
ELSE.
ls_attachment-brelguid = ls_link-brelguid.
ENDIF.
APPEND ls_attachment TO lt_attachment.
WHEN OTHERS.
CONTINUE.
ENDCASE.
ENDLOOP.
IF sy-subrc = 0.
* CALL METHOD create_links
* EXPORTING
* io_bitem = io_bitem
* it_attachment = lt_attachment
* IMPORTING
* et_partner = et_partner
* et_links = et_links.
*
ENDIF.
CATCH cx_obl_parameter_error .
CATCH cx_obl_internal_error .
CATCH cx_obl_model_error .
CATCH cx_root.
ENDTRY.
cta_attachments[] = lt_attachment[].
ENDFORM. "get_item_links

9/9

You might also like