2007 Oct 30 1:34 AM
Is there a way to "read" every file (csv) file in a directory on the server (a background job)? I will never know the number of files on the server during any given run. Is there a way to "loop" through a directory or bring the filenames into a table and loop through that table? Basically I will have many csv files, each one being an order, and I will be processing these files (orders) each night. I realize that I will need to use a dataset but how do I get to the files?
Davis
2007 Oct 30 1:37 AM
Hi,
Please check this sample code.
REPORT ZDIRFILES.
PARAMETER: p_fdir type pfeflnamel DEFAULT '/usr/sap/tmp'.
data: begin of it_filedir occurs 10.
include structure salfldir.
data: end of it_filedir.
START-OF-SELECTION.
* Get Current Directory Listing for OUT Dir
call function 'RZL_READ_DIR_LOCAL'
exporting
name = p_fdir
tables
file_tbl = it_filedir.
* List of files are contained within table it_filedir
loop at it_filedir.
* Here you process the file individually
write: / it_filedir-NAME.
...
endloop.
...
Regards,
Ferry Lianto
Is there a way to "read" every file (csv) file in a directory on the server (a background job)? I will never know the number of files on the server during any given run. Is there a way to "loop" through a directory or bring the filenames into a table and loop through that table? Basically I will have many csv files, each one being an order, and I will be processing these files (orders) each night. I realize that I will need to use a dataset but how do I get to the files?
Davis
2007 Oct 30 1:37 AM
Hi,
Please check this sample code.
REPORT ZDIRFILES.
PARAMETER: p_fdir type pfeflnamel DEFAULT '/usr/sap/tmp'.
data: begin of it_filedir occurs 10.
include structure salfldir.
data: end of it_filedir.
START-OF-SELECTION.
* Get Current Directory Listing for OUT Dir
call function 'RZL_READ_DIR_LOCAL'
exporting
name = p_fdir
tables
file_tbl = it_filedir.
* List of files are contained within table it_filedir
loop at it_filedir.
* Here you process the file individually
write: / it_filedir-NAME.
...
endloop.
...
Regards,
Ferry Lianto
2007 Oct 30 1:55 AM
Ferry, that is beautiful! I could give you a hug for that!!!
A quick follow up. Can you move files and create directories in ABAP?
This would create the directory but what about moving/renaming a file?
call function 'GUI_CREATE_DIRECTORY'
exporting
dirname = '//<ip_address>/qfilesvr400/<host>/usr/sap/TST/SYS/Folder1'
exceptions
failed = 1
others = 2.Davis.
Message was edited by:
Davis
2007 Oct 30 1:56 PM
Hi,
You can use SYSTEM command/function.
DATA: UNIX_COMMAND(500).
DATA: BEGIN OF ITAB OCCURS 0,
LINE(255),
END OF ITAB.
CONCATENATE 'mv' SOURCE_FILE DEST_FILE INTO UNIX_COMMAND
SEPARATED BY SPACE.
CALL 'SYSTEM' ID 'COMMAND' FIELD COMMAND ID 'ITAB' FIELD TABM-*SYS*.
Regards,
Ferry Lianto
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |