on 08-19-2008 3:45 PM
Hi ,
Someone help me with the trick how to read the filenames from a Unix Directory.
Thanks
using LS of unix command you can do this..
LS -al <dir>
lists all files in a directory.
REPORT ZUNIX line-size 400
no standard page heading.
data: unixcom like rlgrap-filename.
unixcom = 'ls -al dir'.
data: begin of tabl occurs 500,
line(400),
end of tabl.
data: lines type i.
*----------------------------------------------------------------------
start-of-selection.
refresh tabl.
call 'SYSTEM' id 'COMMAND' field unixcom
id 'TAB' field tabl[].
"it get the files into the tabl
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No , I don't want to check the given filename . I want to get the list of files in the directory.
This worked....
concatenate 'ls -l' l_path into l_command separated by space.
call 'SYSTEM' id 'COMMAND' field l_command
id 'TAB' field l_t_result[].
Thanks to all
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry any of them did not help . I did not try the answer from Venkataganesh.
It was kind of confusing for me .
but looks like that is the right answer.
Venkata , can you please help me resolve this issue?
Thanks in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
do you want to check only given specific file ?
if so check this fm.......
*This function module checks if the target file exists or not.
CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'
EXPORTING
FNAME = file
IMPORTING
EXIST = v_exist
EXCEPTIONS
FILEINFO_ERROR = 1
OTHERS = 2.
before calling of this fm concatenate the file path and the file name into file.
For F4 help on application directory use function module F4_DXFILENAME_TOPRECURSION
close thread once question is answered.
rgds,
sairam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try these function modules.
This just a piece of code from one of my program.
CALL 'C_DIR_READ_FINISH' " just to be sure
ID 'ERRNO' FIELD wa_file-errno
ID 'ERRMSG' FIELD wa_file-errmsg.
CALL 'C_DIR_READ_START' ID 'DIR' FIELD a_dir_name
ID 'FILE' FIELD a_generic_name
ID 'ERRNO' FIELD file-errno
ID 'ERRMSG' FIELD file-errmsg.
IF sy-subrc <> 0.
Use log application Read Directory failed
Error reading directory &1 (OS returned code : &2)
l_msg_text = text-e01.
REPLACE '&1' WITH a_dir_name INTO l_msg_text.
REPLACE '&1' WITH a_dir_name INTO file-errno.
WRITE 😕 l_msg_text.
sy-subrc = 4.
EXIT.
ENDIF.
DO.
CLEAR file.
CALL 'C_DIR_READ_NEXT'
ID 'TYPE' FIELD file-type
ID 'NAME' FIELD file-name
ID 'LEN' FIELD file-len
ID 'OWNER' FIELD file-owner
ID 'MTIME' FIELD file-mtime
ID 'MODE' FIELD file-mode
ID 'ERRNO' FIELD file-errno
ID 'ERRMSG' FIELD file-errmsg.
file-dirname = a_dir_name.
MOVE sy-subrc TO file-subrc.
CASE sy-subrc.
WHEN 0.
CLEAR: file-errno, file-errmsg.
Regular file type
IF file-type(1) = 'f' OR file-type(1) = 'F'.
IF p_files = 'X'.
TRANSLATE s_files-low USING '* '.
CONDENSE s_files-low NO-GAPS.
IF file-name CS s_files-low.
MOVE-CORRESPONDING file TO wa_file.
APPEND wa_file TO file_list.
ENDIF.
ELSE.
MOVE-CORRESPONDING file TO wa_file.
APPEND wa_file TO file_list.
ENDIF.
ENDIF.
WHEN 1.
End of Directory reached
EXIT.
WHEN OTHERS.
ADD 1 TO error_counter.
IF error_counter > max_errors.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD file-errno
ID 'ERRMSG' FIELD file-errmsg.
IF sy-subrc NE 0.
Application log : Error to call 'C_DIR_READ_FINISH'
ENDIF.
Log in the application log TOO MANY READ ERRORS
EXIT.
ENDIF.
ENDCASE.
ENDDO.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD wa_file-errno
ID 'ERRMSG' FIELD wa_file-errmsg.
IF sy-subrc <> 0.
*_ Write
ENDIF.
Path can be /USR/...
Try this code.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_asfile TYPE rlgrap-filename. " Path of UNIX
SELECTION-SCREEN END OF BLOCK b1.
OPEN DATASET p_asfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET p_asfile INTO wa_emp.
IF sy-subrc 0.
EXIT.
ENDIF.
APPEND wa_emp TO it_emp.
ENDDO.
CLOSE DATASET p_asfile.
Regards,
Bala Krishna.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check...
RZL_READ_DIR
RZL_READ_DIR_GLOBAL
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.