Google Search - Blog...........

ABAP - Report Program To Read Folders & Files In Application Server Directory.

Here is an example for reading all the folders and files in the application server directory . Please let me know if there is any thing needed .



REPORT ZREAD_APPL_FILE_DATA .



*--internal table for the file contents

DATA: BEGIN OF ITAB OCCURS 0,

REC(1000) TYPE C,

END OF ITAB.



DATA: WA(1000) TYPE C,

P_FILE TYPE LOCALFILE,

IT_FILE TYPE TABLE OF SALFLDIR WITH HEADER LINE.



PARAMETERS: P_PATH TYPE SALFILE-LONGNAME

DEFAULT 'F:\usr\sap\EC6\DVEBMGS00\data\'.



*----function module for reading files

* in a directory in the application server



CALL FUNCTION 'RZL_READ_DIR_LOCAL'

EXPORTING

NAME = P_PATH

TABLES

FILE_TBL = IT_FILE

EXCEPTIONS

ARGUMENT_ERROR = 1

NOT_FOUND = 2

OTHERS = 3.



*---here the internal table will have all the files in the directory

LOOP AT IT_FILE.

CONCATENATE P_PATH IT_FILE-NAME INTO P_FILE.

CLEAR ITAB.

REFRESH ITAB.

*--open the file in that directory

OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT .

IF SY-SUBRC = 0.

*--read the contents in the file

DO.

READ DATASET P_FILE INTO WA.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

ITAB-REC = WA.

*---append the contents into an internal table

APPEND ITAB.

ENDDO.

ENDIF.

CLOSE DATASET P_FILE.

*----display the contents in the file

LOOP AT ITAB.

WRITE:/ ITAB.

ENDLOOP.

ENDLOOP.

No comments:

Post a Comment