04-27-2005 5:15 PM
Can someone please explain this code to me?
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.
04-28-2005 7:52 PM
Hi Audrey-
Here is some explanation of this code. I will look into the two FMs as well and let you know if I find detailed information about them.
If this response is satisfactory then please consider assigning some points.
Thanks,
- Vik.
-
data_tab = l_t_data_tab_bin <-- what is in data_tab when the function is done?
This code will load the contents of the file on the frontend PC into the internal backend table itab. The file to be uploaded is specified in parameter filename of this function. In this case it is dynamically assigned from the results of a directory listing and filtering loop (As in, prepare list of files in directory, then filter it out {eg., file of certain extension, etc.}, then loop through the remaining list and assign its value to the function module).
-
l_s_chavl-chavl = dir_entry+0(len). <-- what does this statement do? what does 0(len) mean?
This is placing the value of 'dir_entry' into the field 'chavl' in the internal table/object 'l_s_chavl'
The +0 indicates the starting offset of the source string (so, here it would be from the first character.)
The (len) specifies the length (number of characters) that should be copied from the source string to the target string. (So, here it is some numerical variable 'len' that is being dynamically assined a value in the program when it runs)
-
04-28-2005 8:17 PM
Hi Audrey-
Please some information for the function modules that you needed help with.
If this information helps you out then please reward with some points.
Thanks,
- Vik.
-
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' <-- what does this function do?
The function group 'CONVERSION_EXIT_MATN1_INPUT' is a part of the 'OMCV' function group. It is used mostly by applications working with the 'MM' module. This function group is a collection of function modules for 'Material Number Conversion'. This particular function module is used for 'Material number conversion (INPUT)'. Meaning if you provide it the value 1234 it returns 000000000000001234.
-
CALL FUNCTION 'RSOD_DOC_MAST_CHANGE' <-- how is the file being uploaded in the Document repository?
The function group 'RSOD_DOC_MAST_CHANGE' is a part of the 'RSOD_API' function group. It is used mostly by applications working with documents in BW. This function group is a collection of function modules for working with documents in BW. This particular function module is used for 'Creating Document for Master Data'. You can use this function module to create or change a document for a characteristic value.
-
04-28-2005 8:29 PM
Hi Audrey-
In response to your question about 'how is the file being uploaded in the Document repository?', please look at the two function modules 'GUI_UPLOAD' and 'RSOD_DOC_MAST_CHANGE' being used in this code. What you will notice is that GUI upload returns the binary contents of the file that is being processed to an internal table called 'l_t_data_tab_bin'. Then in the function module 'RSOD_DOC_MAST_CHANGE' you will notice that this internal table is assigned to the table parameter 'i_t_file_content_binary'. This way when you use the latter function module for creating a document for master data, you put into it the binary contents of the file that were acquired through GUI_Upload.
Ofcourse, since this is a batch upload program, it uses loops to repeat the single document upload process many times to handle multiple documents. I hope my posts help you understand the process for one document. After that the loop takes care of the multiple documents.
If you find these responses helpful then please reward with points.
Thank you,
- Vik.
04-29-2005 6:52 AM
Hi Audrey!
ad 1) GUI_UPLOAD reads a (text) file from your PC (or network drive available on your PC). Afterwards data_tab is filled with file content.
ad 2) 'dir_entry+0(len)'? In table dir_tab a list of file names is stored, into variable dir_entry one line is moved. Out of this line a part is taken: from first place ('0') the length len (calculated before dynamically -4): Looks like filename without extension (like .txt or .csv as last four places).
ad 3) This function module converts external material number (like on screen without leading zeros) into internal format (with leading zeros). Strange: filename (without extension) is used as article number.
ad 4) I can't find function 'RSOD_DOC_MAST_CHANGE' (or something similiar) in my system (620). Someone else might help further.
Regards,
Christian
12-09-2005 7:42 AM
hi
Can any one tell me How the flat file for Customer,Vendor, Material Master and Purchase Order. We are doing Migration Project.
You can send your valuable reply to ravi.balakrishnan@tatainfotech.com
12-09-2005 9:12 AM
Hi Ravi,
I think you missed a few words while posting the query.
For uploading a flat file from Legacy to SAP use FM
GUI_UPLOAD
for downloading data from SAP to legacy(flat file), use FM GUI_DOWNLOAD.
Hope this helps....
Lokesh
Pls. reward appropriate points