‎2005 Apr 27 1:00 AM
Hi, is GUI_UPLOAD only used to upload a document from the user's local hard drive?
I have a file on the server and I'm trying to use the GUI_UPLOAD function but sy-subrc returns with and error code of 1. I have verified that the file is in the proper path on the server.
Is there a similar function for upload from a server?
Note... I am modifying the "How To Mass Upload Documents to BW" article (https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/biw/how to mass upload documents to bw). Instead of uploading the files from local hard drive, I put the files on the server and I want to upload the documents from there.
Any help is appreciated!
Thanks!
Message was edited by: Audrey Fong
‎2005 Apr 27 7:55 AM
Hi Audrey,
I usually use this function which is very simple to use.
And yes, it can upload a file from a server.
The code is like that :
with :
parameters : p_filename like rlgrap-filename value 'server001/datasap/test/upload.csv' .
data: filename type string,
t_data type table of string.
filename = p_filename.
call function 'GUI_UPLOAD'
exporting
filename = filename
filetype = 'ASC'
tables
data_tab = t_data
exceptions
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17.
Hope this helps.
Regards,
Erwan.
‎2005 Apr 27 1:46 AM
Hi Audrey--
You can accomplish what you seem to be trying with the 'OPEN DATASET' and 'READ DATASET' commands.
I am attaching sample code below where the program looks inside a folder on the server and creates a list of files matching a certain file extension in that folder on the server. Then the program loops through that list of files and appends/reads their textual contents into an internal table that contains their joined contents.
Hope this helps.
Thanks,
- Vik.
If this solution works- I would appreciate some points.
&----
*& Form get_ocr_data_files
&----
text
----
--> p1 text
<-- p2 text
----
form get_ocr_data_files.
Data: p_fdir type pfeflnamel.
data: begin of it_filedir occurs 10,
NAME(100) type C,
SIZE type PFEFLSIZE.
data: end of it_filedir.
data: begin of it_filedir_goodext occurs 10,
NAME(100) type C,
SIZE type PFEFLSIZE.
data: end of it_filedir_goodext.
data: file_data type xstring.
data: DSN(50) type c value 'TEMPFILE'.
p_fdir = i_ocr1-datalocin.
Get Current Directory Listing for specified Directory
into an internal table it_filedir.
call function 'RZL_READ_DIR_LOCAL'
exporting
name = p_fdir
tables
file_tbl = it_filedir.
Get OCR data file by extension
List of all the files of the specified extension that are contained
within table it_filedir.
loop at it_filedir.
if it_filedir-NAME cs i_ocr1-fextension.
concatenate i_ocr1-datalocin c_cmd_win_ext it_filedir-NAME
into it_filedir-NAME.
it_filedir_goodext-NAME = it_filedir-NAME.
append it_filedir_goodext.
endif.
endloop.
loop at it_filedir_goodext.
move it_filedir_goodext-NAME to DSN.
Read data from file
clear file_data.
open dataset DSN in binary mode.
read dataset DSN into file_data.
close dataset DSN.
i_data_tab-line = file_data.
append i_data_tab.
endloop.
endform. " get_ocr_data_files
‎2005 Apr 27 5:12 PM
Also, this program will eventually be a job which is run on the server.
‎2005 Apr 27 7:51 AM
which server you have loaded the files? is it the sap application server in the unix directory, in such a case you need to use DATASET commands.
but if its on any other server in the file system you can map the path to a drive in your machine and use that path to load the document using gui_upload.
Regards
Raja
‎2005 Apr 27 7:55 AM
Hi Audrey,
I usually use this function which is very simple to use.
And yes, it can upload a file from a server.
The code is like that :
with :
parameters : p_filename like rlgrap-filename value 'server001/datasap/test/upload.csv' .
data: filename type string,
t_data type table of string.
filename = p_filename.
call function 'GUI_UPLOAD'
exporting
filename = filename
filetype = 'ASC'
tables
data_tab = t_data
exceptions
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17.
Hope this helps.
Regards,
Erwan.
‎2005 Apr 27 5:02 PM
Erwan,
Regarding your code?
parameters : p_filename like rlgrap-filename value 'server001/datasap/test/upload.csv' .
What is "server001"?
For example, my server is.. aaa.bbb.ccc.com
and my path on the server where my files are is /home/mstdata_docs
Would my syntax be:
parameters : p_filename like rlgrap-filename value 'aaa/home/mstdata_docs/test.txt' .
Because I tried that and it didn't work.
Please help!
‎2005 Apr 27 5:07 PM
Yes your stntax seems to be good.
and yes "Server001" corresponds to a windows server.
You know sometimes under windows you have shortcuts
eg : "DATA_SAP on SERVER01"
Hope this helps,
Erwan.
‎2005 Apr 27 5:11 PM
My server is a UNIX server. Does GUI_UPLOAD work for unix servers? If so, what is the syntax?
Thanks!
‎2005 Apr 27 5:15 PM
Regarding your code.
Your file is uploaded in a internal table : l_t_data_tab_bin .
Then the 'RSOD_DOC_MAST_CHANGE' function load the table in the doc repository.
- 'CONVERSION_EXIT_MATN1_INPUT' seems not to be important : it enable to delete unwanted leading zero on material number or adding them regarding the Material customizing.
- len = strlen( dir_entry ) - 4.
len contains an integer which correspond to the length of the field 'dir_entry' - 4 (strlen( dir_entry ) returns the length of the field )
‎2005 Apr 27 5:19 PM
If you use a Unix Server, it's better using :
Open dataset ...
Transfer...
Close dataset ...
The right syntax is posted above
‎2005 Apr 27 5:55 PM
Erwan,
I do use dataset statements to access the files on the unix server. I think it would be easier if I paste my code here so you can see what I'm doing...
REPORT ZMAST_DOC_UPLOAD_AF .
DATA: line TYPE string,
cmt_str TYPE string value '',
val TYPE string,
DELIMITER_CMT(1) VALUE '*',
DELIMITER_VAL(1) VALUE '@'.
DATA: dsn_pth TYPE string value '/home/af3464/',
dsn_doc TYPE string,
ext_type TYPE string value '.htm'.
DATA: l_filelength TYPE i,
filename TYPE string,
l_t_data_tab_bin TYPE sdokcntbins.
DATA: len TYPE i.
DATA: l_s_chavl TYPE rsod_s_chanm_chavl,
l_t_chavl TYPE TABLE OF rsod_s_chanm_chavl.
DATA: l_s_content_info TYPE rsod_s_content_info.
DATA: name TYPE skwf_urlp,
l_t_return TYPE bapiret2,
descr TYPE sdok_descr,
l_t_data_tab_asc TYPE sdokcntascs.
parameter src_path(40) lower case.
parameter obj_name(20).
OPEN DATASET src_path IN BINARY MODE FOR INPUT.
DO.
READ DATASET src_path INTO line.
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE: / 'line: ', line.
DO.
IF line = ''.
EXIT.
ENDIF.
*Get next document text.
SPLIT line AT DELIMITER_CMT INTO cmt_str line.
WRITE: / 'line: ', line.
WRITE: / 'cmt_str: ', cmt_str.
*Get master data value.
SPLIT cmt_str AT DELIMITER_VAL INTO val cmt_str.
WRITE: / 'val: ', val.
WRITE: / 'cmt_str: ', cmt_str.
CONCATENATE val ext_type INTO filename.
CONCATENATE dsn_pth filename INTO dsn_doc.
OPEN DATASET dsn_doc IN BINARY MODE FOR OUTPUT.
TRANSFER cmt_str TO dsn_doc.
CLOSE DATASET dsn_doc.
WRITE: / dsn_doc.
len = strlen( filename ) - 4.
REFRESH l_t_chavl.
l_s_chavl-chanm = 'ZWKSTATE'.
l_s_chavl-chavl = filename+0(len).
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = l_s_chavl-chavl
IMPORTING
output = l_s_chavl-chavl
EXCEPTIONS
length_error = 1
OTHERS = 2.
APPEND l_s_chavl TO l_t_chavl.
l_filelength = 31.
l_s_content_info-mimetype = 'application/html'.
l_s_content_info-file_name = filename.
l_s_content_info-file_size = l_filelength.
name = filename.
CLEAR l_t_return.
CALL FUNCTION 'RSOD_DOC_MAST_CHANGE'
EXPORTING
i_chanm = l_s_chavl-chanm
i_chavl = l_s_chavl-chavl
I_DOC_TYPE =
i_description = descr
i_name = name
I_LANGU = SY-LANGU
i_overwrite_mode = if_rsod_const=>mode_replace_phio
i_with_content = 'X'
i_s_content_info = l_s_content_info
I_WITH_URL =
I_URL =
I_COPY_URL_CONTENT =
IMPORTING
E_NAME =
e_s_return = l_t_return
TABLES
i_t_file_content_ascii = l_t_data_tab_asc
i_t_file_content_binary = l_t_data_tab_bin.
IF l_t_return-type = 'E' OR
l_t_return-type = 'W' OR
l_t_return-type = 'A'.
error
WRITE: / filename, text-004, l_t_return-type, l_t_return-id,
l_t_return-number.
ELSE.
successfuly loaded
WRITE: / filename, text-003.
ENDIF.
ENDDO.
ENDDO.
CLOSE DATASET src_path.
I am trying to modify the code given in the MASS UPLOAD DOCUMENTS TO BW article. We have different requirements. We have one file on the server. in that file are different master data values and an associated text which needs to be put in a document. So, I take the text and create a file on the server. This new file needs to be uploaded into the Documents repository.
When I run my program, i get an error. The error is
text-004: E
l_t_return-type: RSOD
l_t_return-id: 169
I'm pretty sure that it doesn't work because the table l_t_data_tab_bin is empty. In the orginal code GUI_UPLOAD poplulates that table. Can someone tell me how put data into this table?
Help is appreciated!
‎2005 Apr 28 4:55 PM
Erwan,
I was finally able to get my program to work.
You helped greatly.
Thank you very much.
‎2005 Apr 27 4:16 PM
Thanks everyone.
I based on what you all are saying, I think I misunderstood what GUI_UPLOAD does. I thought that the function uploads a given file into the Documents repository and later in the code that document in the Document repository is attached to a master data value...
Instead, what I think it means now is that GUI_UPLOAD uploads the file somewhere and then later the program calls RSOD_DOC_MAST_CHANGE to do the upload into the Documents repository. But I am missing something here. Can someone explain to me what is happening after the call to fuction GUI_UPLOAD is done? The entire code is below.
REPORT ZMAST_DOC_UPLOAD .
DATA: l_s_chavl TYPE rsod_s_chanm_chavl.
DATA: l_t_chavl TYPE TABLE OF rsod_s_chanm_chavl.
DATA: l_s_excpt(5) TYPE c.
DATA: l_t_data_tab_asc TYPE sdokcntascs.
DATA: l_t_data_tab_bin TYPE sdokcntbins.
DATA: rc TYPE sy-subrc.
DATA: wa_dir(100). " like file_info.
DATA: day(2) TYPE c.
DATA: l_s_content_info TYPE rsod_s_content_info.
DATA: dir_tab TYPE STANDARD TABLE OF file_info.
DATA: dir_entry(100).
*DATA: p_path(40) type C .
DATA: l_s_peri LIKE t009b-poper.
DATA: l_s_per(2) TYPE c.
TYPES: BEGIN OF fileinfostruc,
material(18),
END OF fileinfostruc.
TYPES: date TYPE sy-datum.
DATA: l_s_year LIKE t009b-bdatj.
DATA: fileinfo TYPE fileinfostruc.
DATA: date TYPE date.
DATA: count TYPE i.
DATA: len TYPE i.
DATA: offset TYPE i.
DATA: id TYPE i.
DATA: filename TYPE string.
DATA: thema TYPE string.
DATA: pfad TYPE c.
DATA: dir TYPE string.
DATA: descr TYPE sdok_descr.
DATA: name TYPE skwf_urlp.
DATA: l_t_return TYPE bapiret2.
DATA: l_filelength TYPE i.
DATA: file_tab TYPE filetable,
single_file TYPE filetable.
DATA: file_line LIKE LINE OF file_tab.
DATA: ls_path TYPE string.
INTERFACE IF_RSOD_CONST LOAD.
PARAMETER p_path(40) OBLIGATORY DEFAULT 'C:\'.
Display file selection dialog
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
PERFORM get_files.
START-OF-SELECTION.
PERFORM section_main.
FORM get_files.
dir = p_path.
DATA: folder TYPE string.
CALL METHOD
cl_gui_frontend_services=>directory_browse
EXPORTING
WINDOW_TITLE =
initial_folder = 'C:\'
CHANGING
selected_folder = folder.
EXCEPTION
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
others = 4
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
p_path = folder.
*fetch all files from directory, use *.doc as mask
CALL METHOD
cl_gui_frontend_services=>directory_list_files
EXPORTING
directory = folder
filter = '*.doc'
files_only = 'X'
DIRECTORIES_ONLY =
CHANGING
file_table = dir_tab
count = count
EXCEPTIONS
cntl_error = 1
directory_list_files_failed = 2
wrong_parameter = 3
error_no_gui = 4
not_supported_by_gui = 5
OTHERS = 6.
ENDFORM. "get_files
&----
*& Form section_main
&----
text
----
FORM section_main.
LOOP AT dir_tab INTO dir_entry.
Build filename
TRANSLATE dir_entry TO UPPER CASE.
CLEAR: filename.
CONCATENATE p_path '\' dir_entry INTO filename.
call upload
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
filetype = 'BIN'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
IMPORTING
filelength = l_filelength
TABLES
data_tab = l_t_data_tab_bin <-- what is in data_tab when the function is done?
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
WRITE: / text-002, sy-subrc, dir_entry.
"Error in uploading File
EXIT.
ENDIF.
fill assignments for material
len = strlen( dir_entry ) - 4.
REFRESH l_t_chavl.
l_s_chavl-chanm = 'ZWKSTATE'.
l_s_chavl-chavl = dir_entry+0(len). <-- what does this statement do? what does 0(len) mean?
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' <-- what does this function do?
EXPORTING
input = l_s_chavl-chavl
IMPORTING
output = l_s_chavl-chavl
EXCEPTIONS
length_error = 1
OTHERS = 2.
APPEND l_s_chavl TO l_t_chavl.
set mime-type
l_s_content_info-mimetype =
'application/msword'.
l_s_content_info-file_name = dir_entry.
l_s_content_info-file_size = l_filelength.
set name and title
name = dir_entry.
CLEAR l_t_return.
upload document
CALL FUNCTION 'RSOD_DOC_MAST_CHANGE' <-- how is the file being uploaded in the Document repository?
EXPORTING
i_chanm = l_s_chavl-chanm
i_chavl = l_s_chavl-chavl
I_DOC_TYPE =
i_description = descr
i_name = name
I_LANGU = SY-LANGU
i_overwrite_mode =
if_rsod_const=>mode_replace_phio
i_with_content = 'X'
i_s_content_info = l_s_content_info
I_WITH_URL =
I_URL =
I_COPY_URL_CONTENT =
IMPORTING
E_NAME =
e_s_return = l_t_return
TABLES
i_t_file_content_ascii = l_t_data_tab_asc
i_t_file_content_binary = l_t_data_tab_bin.
IF l_t_return-type = 'E' OR
l_t_return-type = 'W' OR
l_t_return-type = 'A'.
error
WRITE: / dir_entry(25), text-004, l_t_return-type, l_t_return-id,
l_t_return-number.
ELSE.
successfuly loaded
WRITE: / dir_entry(25), text-003.
ENDIF.
ENDLOOP.
ENDFORM. "section_main
This code is from https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/biw/how%20to%20mas...
My questions are on the right side of the code.
Thanks!