‎2006 Nov 02 3:45 PM
Hi ,
I have a requirement to read more than one file that have the name for e.g abc*.txt from the application server. The program has to read all the files one by one that has the name that starts with 'abc' and file type .txt. All the files to be put into one internal table of line type string for further processing. Please suggest me a suitable solution for this req.
Thanks for your help in advance.
Kannan.
‎2006 Nov 02 4:11 PM
‎2006 Nov 02 4:01 PM
this code will serve your purpose.
IF P_AFILE CS '.csv'.
LV_FILENAME = P_AFILE.
TRANSLATE LV_FILENAME TO LOWER CASE.
IF P_AFILE CS SY-SYSID.
TRANSLATE LV_FILENAME+SY-FDPOS(3) TO UPPER CASE.
ENDIF.
*-- Open Dataset
OPEN DATASET LV_FILENAME FOR INPUT IN TEXT MODE.
IF SY-SUBRC EQ 0.
IT_FILELIST-FILE_NAME = P_AFILE.
APPEND IT_FILELIST.
ENDIF.
ELSEIF P_AFILE CS '*'.
DG_UNIX_LOC(9) = 'ls *.csv '.
DG_UNIX_LOC+9(45) = P_AFILE.
DATA : V_STRING(100) TYPE C.
REFRESH DT_TABL.
CALL 'SYSTEM' ID 'COMMAND' FIELD DG_UNIX_LOC
ID 'TAB' FIELD DT_TABL-SYS.
LOOP AT DT_TABL.
IF DT_TABL-LINE CS 'batch/data/inb/sec-cam/sec-cam'.
IT_FILELIST-FILE_NAME = DT_TABL-LINE.
APPEND IT_FILELIST.
ENDIF.
ENDLOOP.
ELSE.
MESSAGE I000 WITH 'Either the File Name or File Path'
'is Wrong Please check Entry'.
STOP.
ENDIF.
***
DESCRIBE TABLE IT_FILELIST LINES V_TOTALFILES.
IF NOT IT_FILELIST IS INITIAL.
LOOP AT IT_FILELIST.
LV_FILENAME = IT_FILELIST-FILE_NAME.
TRANSLATE LV_FILENAME TO LOWER CASE.
IF P_AFILE CS SY-SYSID.
TRANSLATE LV_FILENAME+SY-FDPOS(3) TO UPPER CASE.
ENDIF.
***
*-- Open Dataset
OPEN DATASET LV_FILENAME FOR INPUT IN TEXT MODE MESSAGE MSG.
IF SY-SUBRC EQ 0.
REFRESH: IT_DATA2,
IT_ERROR,
IT_HISTORY,
IT_DATA,
IT_DATA1.
DO.
*-- Read Dataset and Populate Input file data to Internal Table
READ DATASET LV_FILENAME INTO IT_DATA2.
IF SY-SUBRC EQ 0.
*-- Append and Initialize table
APPEND IT_DATA2.
CLEAR IT_DATA2.
ELSE.
*-- Exit Out of DO loop if READ is unsuccess
EXIT.
ENDIF.
ENDDO.
*-- Close Dataset
CLOSE DATASET LV_FILENAME.
Delete File in Actual Run ONLY
IF P_TRUN IS INITIAL.
Delete the File
DELETE DATASET LV_FILENAME.
ENDIF.
IF IT_INPUT[] IS INITIAL.
IF IT_DATA2[] IS INITIAL.
STOP.
ELSE.
*-- Populate History Table
IT_HISTORY[] = IT_INPUT[].
PERFORM PROCESS_FILES USING LV_FILENAME.
ENDIF.
ELSE.
*-- Go to the End of Selection
STOP.
ENDIF.
ENDLOOP.
ELSE.
MESSAGE I000 WITH 'Either the Specified file does not exist'
'or the Directory is Empty'.
STOP.
ENDIF.
‎2006 Nov 02 4:07 PM
HI Kannan
Using FM: <b>EPS_GET_DIRECTORY_LISTING</b>, we can get the list of files existing in a directory.
Get the file names into an internal table.
Now for each entry in the table, open the file append to an internal table of string.
Hope this gives you some idea.
Kind Regards
Eswar
‎2006 Nov 02 4:44 PM
Hi Easwar,
Thanks for your reply. I am trying to test this FM but i could not, as it throwe an error message saying invalid directory or read direcoty failed. Can you please provide me some tips on the input parameters of this FM?
Thanks and Regards,
Kannan.
‎2006 Nov 02 4:11 PM