Generic Object Services.docx
《Generic Object Services.docx》由会员分享,可在线阅读,更多相关《Generic Object Services.docx(20页珍藏版)》请在冰豆网上搜索。
GenericObjectServices
GenericObjectServices(Upload,Download,List)Programatically
可见性:
任何人
IrecentlyfoundmyselfneedingtowriteawebapplicationthatneededtointeractwiththeattachmentsstoredinGenericObjectServiceswithinSAP. TheGenericObjectServicesareusedthroughoutmultipleapplicationareaswithinSAPandhavemanyfeatureswhichincludedocument(object)management. Ifyouhaveeverseenthisicon whileusinganSAPtransaction,thenyouhavetheabilitytousetheGenericObjectServicesintheparticularbusinessprocess. Mygoalwastobeabletocreateanddownloadthedocumentsfromwithinmywebapplication. Inordertodothis,Icreatedsomeclassestohelpme. Iwilltrytodescribethembelow.
Note:
YouwillalwaysneedthebusinessobjectkeydataregardingwhichobjecttypeyouareworkingwithwhilecodingforGenericObjectServices. Forexample,ifyouwereusingGenericObjectServicesfromtransactionPA30(HumanResources),theobjectkeywouldbeBUS1065. IfyouwereusingGenericObjectServicesinOrders(transactionIW33),theobjectkeywouldbeBUS2088. ThiskeycaneasilybedeterminedbyplacingabreakpointinclassCL_BINARY_RELATIONandmethodREAD_LINKS_OF_BINRELSpriortoexecutingtheiconabove.
GOS_GET_FILE_LISTStaticMethodPublicgetattachmentslist
LOG_MSGStaticMethodPrivategenericlog
GOS_ATTACH_FILEStaticMethodPublicuploadattachmentsfile
GOS_DOWNLOAD_FILEStaticMethodPublicdownloadattachmentsfile
FirstIcreatedthefollowingmethod:
GOS_GET_FILE_LIST
ThismethodallowedmetoshowalistofallfilescurrentlyattachedtotheobjectIwasworkingwith. Thismethodcouldbeawrapperaroundstandardfunctionmodule:
BDS_GOS_CONNECTIONS_GET. Ifyoucallthismethodwithyourobjectkey,youwillretrievealistingofallattachments. Ichosetowritethefollowingmethodcodeinstead:
OBJTYPEImportingTypeSWO_OBJTYPTypeofObjectsinPersistentObjectReferences
OBJKEYImportingTypeSWO_TYPEIDInstanceIdent.inBORCompat.PersistentObjectReferences
T_ATTACHMENTSExportingTypeZ_TT_SOODattachments
ES_RETURNChangingTypeZVNT_ST_RETURNReturnmessage
methodgos_get_file_list.
types:
beginofts_key,
foltptypeso_fol_tp,
folyrtypeso_fol_yr,
folnotypeso_fol_no,
objtptypeso_obj_tp,
objyrtypeso_obj_yr,
objnotypeso_obj_no,
forwardertypeso_usr_nam,
endofts_key,
beginofts_attachment,
foltptypeso_fol_tp,
folyrtypeso_fol_yr,
folnotypeso_fol_no,
objtptypeso_obj_tp,
objyrtypeso_obj_yr,
objnotypeso_obj_no,
brelguidtypeoblguid32,
roletypetypeoblroltype,
endofts_attachment,
tt_attachmenttypetableofts_attachment.
data:
ta_srgbtbreltypestandardtableofsrgbtbrel,
wa_srgbtbreltypesrgbtbrel,
lta_soodtypestandardtableofsood,
lwa_soodtypesood,ltp_pathin(1000)typec,
ltp_filenametypestring,
ltp_sortfieldtypechar30,
lta_objconttypesoli_tab,
lta_attachmentstypett_attachment,
lwa_attachmentslikelineoflta_attachments,
lo_boritemtypereftocl_sobl_bor_item,
lo_al_itemtypereftocl_gos_al_item,
li_linktypereftoif_browser_link,
ls_optiontypeobl_s_relt,
lt_optionstypeobl_t_relt,
ls_keytypets_key,
ls_attachmenttypets_attachment,
lt_attachmenttypett_attachment,
lt_linkstypeobl_t_link,
ls_link typeobl_s_link,
lp_linkidtypeblnk_inst,
gs_lportypesibflporb.
ifnotobjtypeisinitialandnotobjkeyisinitial.
select*fromsrgbtbrelintotableta_srgbtbrel
whereinstid_aeqobjkey
andtypeid_aeqobjtype
andcatid_a eq'BO'.
ifsy-subrceq0.
sortta_srgbtbrelbyinstid_atypeid_acatid_a.
deleteadjacentduplicatesfromta_srgbtbrelcomparinginstid_atypeid_acatid_a.
loopatta_srgbtbrelintowa_srgbtbrel.
clear:
lt_attachment[],lta_attachments[].
gs_lpor-instid=wa_srgbtbrel-instid_a.
gs_lpor-typeid=wa_srgbtbrel-typeid_a.
gs_lpor-catid =wa_srgbtbrel-catid_a.
ls_option-sign='I'.
ls_option-option='EQ'.
ls_option-low='ATTA'.
appendls_optiontolt_options.
ls_option-low='NOTE'.
appendls_optiontolt_options.
ls_option-low='URL'.
appendls_optiontolt_options.
try.
callmethodcl_binary_relation=>read_links_of_binrels
exporting
is_object =gs_lpor
it_relation_options=lt_options
ip_role ='GOSAPPLOBJ'
importing
et_links =lt_links.
loopatlt_linksintols_link.
casels_link-typeid_b.
when'MESSAGE'.
ls_key=ls_link-instid_b.
move-correspondingls_keytols_attachment.
ls_attachment-roletype=ls_link-roletype_b.
ifls_link-brelguidisinitial.
ls_attachment-brelguid=ls_link-relguidold.
else.
ls_attachment-brelguid=ls_link-brelguid.
endif.
appendls_attachmenttolt_attachment.
whenothers.
continue.
endcase.
endloop.
catchcx_obl_parameter_error.
catchcx_obl_internal_error.
catchcx_obl_model_error.
catchcx_root.
endtry.
endloop.
lta_attachments[]=lt_attachment[].
checklines(lta_attachments)>0.
select*fromsoodintotablelta_sood
forallentriesinlta_attachments
where
objtp=lta_attachments-objtp and
objyr=lta_attachments-objyr and
objno=lta_attachments-objno.
ifsy-subrceq0.
t_attachments[]=lta_sood.
es_return-text='SUCCESS'.
endif.
datarcodetypei.
dataobjhead_tabtypetableofsoli.
dataobjcont_tabtypetableofsoli.
dataobjpara_tabtypetableofselc.
dataobjparb_tabtypetableofsoop1.
datasood_keytypesoodk.
datahex_modetypesonv-flag.
field-symbolstypelineofz_tt_sood.
loopatt_attachmentsassigning.
ifnot(-objtpisinitialor-objyrisinitialor-objnoisinitial).
concatenate-objtp-objyr-objnointosood_key.
performsocx_selectinprogramsapfsso0
tablesobjhead_tabobjcont_tab
objpara_tabobjparb_tab
using sood_key
hex_mode
rcode.
ifrcodeeq0.
datamofftypei.
datal_param_searchtypesoli-line.
datal_param_headtypesoli-line.
datavaluetypesoli-line.
datawa_objhead_tablikelineofobjhead_tab.
datalt_url_tabtypetableofso_url.
datald_url_tab_sizetypesytabix.
l_param_search='&SO_FILENAME'.
translatel_param_searchtouppercase.
loopatobjhead_tabintowa_objhead_tab.
clearmoff.
find'='inwa_objhead_tab-linematchoffsetmoff.
checksy-subrc=0.
l_param_head=wa_objhead_tab-line(moff).
translatel_param_headtouppercase.
ifl_param_head=l_param_search.
add1tomoff.
value=wa_objhead_tab-line+moff.
ifnot(valueisinitial).
splitvalueat'.'intotablelt_url_tab.
describetablelt_url_tablinesld_url_tab_size.
ifld_url_tab_sizegt1.
readtablelt_url_tabindexld_url_tab_sizeinto-acnam.
endif.
endif.
endif.
endloop.
endif.
endif.
endloop.
else.
callmethodzcl_oh_my_gos=>log_msg
exporting
i_code ='001'
i_v1 ='TherearenoAttachmentsonthisBusinessObject'
receiving
rs_return=es_return.
endif.
else.
callmethodzcl_oh_my_gos=>log_msg
exporting
i_code ='021'
i_v1 ='NoBusinessObjectand/orKeySpecified'
receiving
rs_return=es_return.
endif.
endmethod.
TestingThisMethod:
Hereissomereportsourcecodetotestthemethodviaaprogram:
report ztest_file_list.
data:
ta_srgbtbreltypestandardtableofsrgbtbrel,wa_srgbtbreltypesrgbtbrel,
lta_soodtypestandardtableofsood,lwa_soodtypesood.
parameters:
p_keytypeswo_typeidobligatorydefault'000030026122',
p_typetypeswo_objtypobligatorydefault'BUS2088'.
start-of-selection.
data:
t_st_returntypezvnt_st_return.
callmethodzcl_oh_my_gos=>gos_get_file_list
exporting
objtype =p_type
objkey =p_key
importing
t_attachments=lta_sood
changing
es_return =t_st_return.
ift_st_return-codeisinitial.
datadec_kbtypep.
loopatlta_soodintolwa_sood.
dec_kb=lwa_sood-objlen/1024.
ifdec_kb<1.
dec_kb=1.
endif.
write:
/lwa_sood-objdes,dec_kb,'KB'.
endloop.
else.
messaget_st_retur