REPORT z_barry_055.
INCLUDE : .
PARAMETERS:
p_botype LIKE SWOTENTRY-objtype DEFAULT 'BUS1001001',
p_bo_id LIKE mara-matnr DEFAULT '000000000001100118',
fr_file(128) DEFAULT 'C:\abcde.txt' LOWER CASE .
DATA: p_docty LIKE borident-objtype VALUE 'MESSAGE' ,
p_reltyp LIKE breltyp-reltype VALUE 'ATTA' ,
p_msgtyp LIKE sofm-doctp VALUE 'EXT' .
* p_msgtyp LIKE sofm-doctp VALUE 'JPG' . "DOC TXT ....
* TXT等扩展名会有问题,具体见FM:SO_DOC_INSERT_WITH_ORIG_API1
* 第151行
* IF-IS-RAW-EXT DOCUMENT_....
TYPES: BEGIN OF ty_message_key,
foltp TYPE so_fol_tp,
folyr TYPE so_fol_yr,
folno TYPE so_fol_no,
doctp TYPE so_doc_tp,
docyr TYPE so_doc_yr,
docno TYPE so_doc_no,
fortp TYPE so_for_tp,
foryr TYPE so_for_yr,
forno TYPE so_for_no,
END OF ty_message_key.
TYPES : BEGIN OF ty_binary,
binary_field(255) TYPE c,
END OF ty_binary.
DATA : lt_binary TYPE TABLE OF ty_binary WITH HEADER LINE.
DATA : lv_message_key TYPE ty_message_key.
DATA : lo_message TYPE swc_object.
DATA : lv_doc_size TYPE i.
DATA : fn_upload TYPE string,
filepath LIKE dbmsgora-filename ,
file_name LIKE sdbah-actid ,
file_ext LIKE sdbad-funct .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR fr_file.
PERFORM get_pc_filename.
START-OF-SELECTION.
filepath = fr_file.
CALL FUNCTION 'SPLIT_FILENAME'
EXPORTING
long_filename = filepath
IMPORTING
pure_filename = file_name
pure_extension = file_ext.
p_msgtyp = file_ext.
TRANSLATE p_msgtyp TO UPPER CASE.
swc_create_object lo_message 'MESSAGE' lv_message_key.
DATA BEGIN OF lt_message_container OCCURS 0.
INCLUDE STRUCTURE swcont.
DATA END OF lt_message_container.
swc_set_element lt_message_container 'DOCUMENTTITLE' file_name.
swc_set_element lt_message_container 'DOCUMENTLANGU' sy-langu.
swc_set_element lt_message_container 'NO_DIALOG' 'X'.
swc_set_element lt_message_container 'DOCUMENTNAME' p_docty.
swc_set_element lt_message_container 'DOCUMENTTYPE' p_msgtyp.
* swc_set_element lt_message_container 'FILEEXTENSION' 'JPG'.
fn_upload = fr_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = fn_upload
filetype = 'BIN'
IMPORTING
filelength = lv_doc_size
TABLES
data_tab = lt_binary[].
swc_set_table lt_message_container 'DocumentContent' lt_binary.
swc_set_element lt_message_container 'DOCUMENTSIZE' lv_doc_size.
swc_refresh_object lo_message.
swc_call_method lo_message 'CREATE' lt_message_container.
swc_get_object_key lo_message lv_message_key.
DATA: lo_is_object_a TYPE borident.
lo_is_object_a-objkey = p_bo_id.
lo_is_object_a-objtype = p_botype.
DATA: lo_is_object_b TYPE borident.
lo_is_object_b-objkey = lv_message_key.
lo_is_object_b-objtype = p_docty.
CALL FUNCTION 'BINARY_RELATION_CREATE'
EXPORTING
obj_rolea = lo_is_object_a
obj_roleb = lo_is_object_b
relationtype = p_reltyp
EXCEPTIONS
OTHERS = 1.
COMMIT WORK AND WAIT.
*&--------------------------------------------------------------------*
*& Form get_pc_filename
*&--------------------------------------------------------------------*
FORM get_pc_filename.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
mask = ',*.* ,*.*.'
mode = '0'
title = 'Get the file name'
IMPORTING
filename = fr_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE '文件名错误!' TYPE 'E'.
ENDIF.
ENDFORM. " GET_PC_FILENAME
阅读(5377) | 评论(0) | 转发(0) |