程序中下载采购申请的附件
一、可以對采購申請掛載附件,通過兩種方式:
1、使用GOS,直接掛附件,GOS這個名詞比較唬人,其實就是在PR界面上使用?創建附件,注釋等.這樣掛載的附件只能掛到某個PR上,不能對行項目掛附件。
2、使用DMS,可以細到對行項目掛附件。(沒用過,目前沒空研究)
二、使用第一個方式管理附件的話,有的報表程序可能需要下載PR對應的附件到前臺目錄(前臺指定目錄和文件名),或者下載到某個local PC目錄,或者寫文件到application server路徑下。
首先要知道的是這種方式下相關的透明表:
SRGBTBREL 文檔鏈接,字段INSTID_A、INSTID_B
SOOD SAPoffice: 對象定義,字段OBJTP 文檔類別代碼, OBJYR 對象: 來自 ID 的年份, OBJNO 對象: 來自 ID 的號碼, OBJDES 內容的簡短描述, FILE EXT PC 應用程序的文件擴展名。
1、如果程序中需要在前臺保存附件,可以使用class:
CL_GOS_DOCUMENT_SERVICE,
method:EXPORT_ATTACHMENT
2、下載到某個local PC目錄
使用FM:GUI_DOWNLOAD,如果是純文本的文件,可以使用BAPI_REL_GETRELATIONS獲得對象鏈接,然后SO_OBJECT_READ獲得文本對象的內容。如果是二進制文件,如圖片,doc文件,pdf文件等,則處理較為復雜,需要BAPI_REL_GETRELATIONS,SO_OBJECT_READ,SO_KPRO_DATA_FROM_OBJCONT_GET,SO_LOIO_PHIO_GET,SDOK_PHIO_LOAD_CONTENT,SCMS_BINARY_TO_XSTRING幾個FM。
3、寫文件到application server路徑,如寫到/usr/ttt/目錄下以供他用
如2中獲得對象內表,然后使用open dataset方式寫文件,以下例子:
FORM frm_download_atta? USING??? p_it_zmmjy_th_pr STRUCTURE zmmjy_th_pr
??????????????????????????????????????????????? p_g_path? ”路徑/usr/ttt/
??????????????????????????????????? CHANGING p_flag??? ”PR是否有附件
?????????????????????????????????????????????????? p_ftype .
DATA: l_objectid TYPE bapiborid,
??????? lt_relat TYPE TABLE OF bapirellk WITH HEADER LINE,
??????? l_objdisp TYPE sood2,
??????? lt_objcont TYPE TABLE OF soli,
??????? lt_context LIKE sdokpropty OCCURS 0 WITH HEADER LINE,
??????? loio_object LIKE sdokobject,
??????? phio_object LIKE sdokobject,
??????? lt_binary_content TYPE TABLE OF sdokcntbin,
??????? xfile TYPE xstring,
??????? xfilename TYPE string.
DATA: xlen TYPE i.
DATA t_banfn LIKE eban-banfn.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input? = p_it_zmmjy_th_pr-banfn
IMPORTING
output = t_banfn.
? l_objectid-objkey = t_banfn.
? l_objectid-objtype = 'BUS2105'.
? p_flag = 'X'.
CALL FUNCTION 'BAPI_REL_GETRELATIONS'
EXPORTING
????? objectid??????? = l_objectid
????? relation??????? = 'ATTA'"附件,除此之外還有NOTE,URL等
TABLES
????? listofrelations = lt_relat[].
IF LINES( lt_relat ) = 0."沒有附件
??? p_flag = ''.
EXIT.
ENDIF.
*? LOOP AT lt_relat.
READ TABLE lt_relat INDEX 1."業務上規定附件只有一個
REFRESH lt_objcont.
CALL FUNCTION 'SO_OBJECT_READ'
EXPORTING
????? folder_id???????? = lt_relat-objkey_b(17)
????? object_id???????? = lt_relat-objkey_b+17(17)
IMPORTING
????? object_hd_display = l_objdisp
TABLES
????? objcont?????????? = lt_objcont
EXCEPTIONS
OTHERS??????????? = 15.
MOVE l_objdisp-file_ext TO p_ftype .
TRANSLATE l_objdisp-file_ext TO UPPER CASE.
CALL FUNCTION 'SO_KPRO_DATA_FROM_OBJCONT_GET'
IMPORTING
????? loio_object?????? = loio_object
TABLES
????? objcont?????????? = lt_objcont
????? context?????????? = lt_context
EXCEPTIONS
????? missing_kpro_data = 1
OTHERS??????????? = 2.
CALL FUNCTION 'SO_LOIO_PHIO_GET'
EXPORTING
????? loio_object??????? = loio_object
IMPORTING
????? phio_object??????? = phio_object
EXCEPTIONS
????? kpro_inconsistency = 1
????? x_error??????????? = 2
OTHERS???????????? = 3.
CALL FUNCTION 'SDOK_PHIO_LOAD_CONTENT'
EXPORTING
????? object_id?????????? = phio_object
TABLES
????? file_content_binary = lt_binary_content
EXCEPTIONS
????? not_existing??????? = 1
????? not_authorized????? = 2
????? no_content????????? = 3
????? bad_storage_type??? = 4
OTHERS????????????? = 5.
? xlen = l_objdisp-objlen.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
????? input_length = xlen
IMPORTING
buffer?????? = xfile
TABLES
????? binary_tab?? = lt_binary_content
EXCEPTIONS
????? failed?????? = 1
OTHERS?????? = 2.
DATA sap_path_n TYPE string.
DATA wa LIKE sdokcntbin.
CONCATENATE p_g_path? p_it_zmmjy_th_pr-filename '.' p_ftype INTO sap_path_n.
OPEN DATASET sap_path_n FOR OUTPUT IN BINARY MODE.
IF sy-subrc NE 0.
MESSAGE 'OPEN FILE FAILED' TYPE 'E'.
ENDIF.
LOOP AT lt_binary_content INTO wa.
TRANSFER wa-line TO sap_path_n.
ENDLOOP.
CLOSE DATASET sap_path_n.
CLEAR sap_path_n.
*? ENDLOOP.
ENDFORM.?
三、可以用事務碼OAOR管理附件
以PR為例,
三、若DMS管理附件,怎么下載附件,候補
總結
以上是生活随笔為你收集整理的程序中下载采购申请的附件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用CL_GOS_DOCUMENT_SE
- 下一篇: webdynpro GOS BDS 文档