FUNCTION zfi001_dms_upload.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(IV_BUKRS) LIKE ANLA-BUKRS OPTIONAL
*" VALUE(IV_ANLN1) LIKE ANLA-ANLN1 OPTIONAL
*" VALUE(IV_ANLN2) LIKE ANLA-ANLN2 OPTIONAL
*" EXPORTING
*" VALUE(ES_RETURN) LIKE BAPIRET2 STRUCTURE BAPIRET2
*" VALUE(EV_DOCNUMBER) LIKE BAPI_DOC_AUX-DOCNUMBER
*"----------------------------------------------------------------------
*========================= 上传文档=============================
* 文档类型
CONSTANTS: con_dokar(3) VALUE 'H03'.
* 存储类别
CONSTANTS: con_storage_cat(10) VALUE 'ZSHINI02'.
DATA: lv_fullname TYPE filep,
lv_dokna TYPE filep,
lv_dokpa TYPE filep.
DATA: lv_answer,
lv_rc TYPE i,
lt_filetable TYPE filetable WITH HEADER LINE.
DATA: l_actualversion TYPE bapi_doc_aux-docversion.
DATA: lv_docnumber TYPE bapi_doc_aux-docnumber.
DATA:
ls_documentdata TYPE bapi_doc_draw2,
ls_documentdatax TYPE bapi_doc_drawx2,"bapi_doc_draw2x,
ls_return TYPE bapiret2.
DATA:
lt_objectlinks TYPE TABLE OF bapi_doc_drad,
ls_objectlinks TYPE bapi_doc_drad,
lt_documentfiles TYPE TABLE OF bapi_doc_files2 WITH HEADER LINE. "外部给号
CLEAR:es_return,ev_docnumber.
*选择本地文件
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = '请选择文件'
multiselection = 'X'
file_filter = '(*.xlsx;*.xls;*.PDF;*.doc;*.docx)|*.xlsx;*.xls;*.PDF;*.doc;*.docx|'
CHANGING
file_table = lt_filetable[]
rc = lv_rc
EXCEPTIONS
OTHERS = 5.
CHECK sy-subrc EQ 0 AND lv_rc GT 0.
* 获取选择的文件名
READ TABLE lt_filetable INDEX 1.
CHECK sy-subrc EQ 0.
LOOP AT lt_filetable.
PERFORM frm_split_path_file USING lt_filetable-filename
CHANGING lv_dokna "文档名称
lv_dokpa."文档路径
PERFORM frm_get_doctype USING lv_dokna
CHANGING lt_documentfiles-wsapplication.
lt_documentfiles-documenttype = con_dokar.
lt_documentfiles-storagecategory = con_storage_cat.
lt_documentfiles-docpath = lv_dokpa.
lt_documentfiles-docfile = lv_dokna.
lt_documentfiles-checkedin = 'X'.
APPEND lt_documentfiles.
ENDLOOP.
*CONCATENATE 'AM' zsam_al-applyno INTO
ls_documentdata-documentnumber = ''.
ls_documentdata-documenttype = con_dokar.
ls_documentdata-documentversion = '00'.
ls_documentdata-documentpart = '000'.
ls_documentdata-description = lv_dokna.
ls_documentdata-username = sy-uname.
"分配固定资产对象
CLEAR:lt_objectlinks,ls_objectlinks.
ls_objectlinks-objecttype = 'ANLA'.
ls_objectlinks-objectkey(4) = iv_bukrs.
ls_objectlinks-objectkey+4(12) = iv_anln1.
ls_objectlinks-objectkey+16(4) = iv_anln2.
APPEND ls_objectlinks TO lt_objectlinks.
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
documentdata = ls_documentdata
IMPORTING
documentnumber = ev_docnumber
return = ls_return
TABLES
objectlinks = lt_objectlinks
documentfiles = lt_documentfiles.
IF ev_docnumber NE ''.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDFUNCTION.
FORM frm_get_doctype USING p_dokna
CHANGING p_wsapplication.
DATA: lt_match TYPE match_result_tab,
ls_match LIKE LINE OF lt_match.
FIND ALL OCCURRENCES OF '.' IN p_dokna
IN CHARACTER MODE RESULTS lt_match.
IF NOT lt_match IS INITIAL.
LOOP AT lt_match INTO ls_match.
ENDLOOP.
ADD 1 TO ls_match-offset.
p_wsapplication = p_dokna+ls_match-offset.
TRANSLATE p_wsapplication TO UPPER CASE.
IF p_wsapplication = 'XLSX'.
p_wsapplication = 'XLS'.
ELSEIF p_wsapplication = 'DOC' OR p_wsapplication = 'DOCX'.
p_wsapplication = 'WRD'.
ENDIF.
ENDIF.
ENDFORM. " FRM_GET_DOCTYPE
FORM frm_split_path_file USING uv_fullname
CHANGING cv_filename
cv_pathname.
DATA: lt_match TYPE match_result_tab,
ls_match LIKE LINE OF lt_match.
FIND ALL OCCURRENCES OF '\' IN uv_fullname
IN CHARACTER MODE RESULTS lt_match.
IF NOT lt_match IS INITIAL.
LOOP AT lt_match INTO ls_match.
ENDLOOP.
ADD 1 TO ls_match-offset.
cv_pathname = uv_fullname(ls_match-offset).
cv_filename = uv_fullname+ls_match-offset.
ENDIF.
"可用函数进行分割SO_SPLIT_FILE_AND_PATH
ENDFORM. " FRM_SPLIT_PATH_FILE
阅读(917) | 评论(0) | 转发(0) |