Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reading Multiple Files From Application Server

Former Member
0 Likes
4,072

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.

1 ACCEPTED SOLUTION
Read only

ferry_lianto
Active Contributor
0 Likes
1,528

Hi Kannan,

Please check this threads for solution.

Regards,

Ferry Lianto

4 REPLIES 4
Read only

Former Member
0 Likes
1,528

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.

Read only

Former Member
0 Likes
1,528

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

Read only

0 Likes
1,528

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.

Read only

ferry_lianto
Active Contributor
0 Likes
1,529

Hi Kannan,

Please check this threads for solution.

Regards,

Ferry Lianto