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

Dynamically Reading Files From Application Server

Former Member
0 Likes
2,476

Hi Experts,

Presently I have to write a program which reads files from the application server dynamically. This program will be scheduled in the background with the frequency of half an hour.

I am Using the function module

CALL FUNCTION 'SUBST_GET_FILE_LIST'

EXPORTING

DIRNAME = '/usr/sap/xxx/xxx/'

FILENM = 'DATASET'

PATTERN = '.txt'

TABLES

FILE_LIST = IT_FILELIST

I am facing problem in specifying the parameter FILENM in the function module,

As I have to read many files from the apps server. How to assign the parameter of function module so it can take the many files generated in the apps server.

Thanks in Advance,

Regards,

Irfan Hussain

10 REPLIES 10
Read only

hymavathi_oruganti
Active Contributor
0 Likes
1,438

many files means?

what is the parameter u want to assign.

the above fn module returns all the files in the specified directory in application server.

if u need all files, u can specify like below

CALL FUNCTION 'SUBST_GET_FILE_LIST'

EXPORTING

DIRNAME = P_INPUTPATH

FILENM = '*'

PATTERN = P_lv_pattern

TABLES

FILE_LIST = P_LT_FILE_LIST

EXCEPTIONS

ACCESS_ERROR = 1

OTHERS = 2.

(u can give pattern also '*')

Message was edited by: Hymavathi Oruganti

Read only

0 Likes
1,438

Hi,

I will be getting the files in the application server,

when ever the program is excuted, i need to collect the files and process the data in those files.

During debugging I am able to find that files are not getting accumulated in the internal table.

Basciallay I need to get names of all the files in the internal table and perform the operation.

Message Edited By -Irfan

Regards,

Irfan Hussain

Read only

0 Likes
1,438

the fn module u r using gives all the files in the specified direcorty.

u can give '*' as i said to get all the files.

Read only

0 Likes
1,438

Hi,

I tried with it , but I observed during debugging that

files are getting uploaded with the directory name, not with the file name.

File name is important to me,based on that file convension i need to perform the operation.

CALL FUNCTION 'SUBST_GET_FILE_LIST'

EXPORTING

DIRNAME = '/usr/sap/xx/xx/'

FILENM = '*'

PATTERN = '*'

TABLES

FILE_LIST = IT_FILELIST.

In the internal table During debugging I am able to see

some entries with 'usr/sap/xx/xx/' but i need to see the file name also , so that i can search for a particular string and perform the operation accordingly.

Regards,

Irfan Hussain

Read only

0 Likes
1,438

u declare

DATA: it_FILELIST LIKE RSFILLST occurs 0.

CALL FUNCTION 'SUBST_GET_FILE_LIST'

EXPORTING

DIRNAME = '/usr/sap/xx/xx/'

FILENM = '*'

PATTERN = '*'

TABLES

FILE_LIST = IT_FILELIST.

NOW,

IF U USE

read it_filelist, u can see file name too.

Read only

Former Member
0 Likes
1,438

Hi,

Instead of the above FM, you can use the following code :

AT SELECTION-SCREEN ON VALUE-REQUEST FOR po_ifile.

PERFORM get_current_directory USING 'PO_IFILE' po_ifile

rov-home_dir rov-curr_dir.

PERFORM get_filename-of-server TABLES itab_filename

USING rov-curr_dir rov-gen_name.

PERFORM help_values_get_with_table_ext TABLES itab_filename

USING rov-curr_dir

po_ifile.

&----


*& Form get_current_directory

&----


  • text

----


  • -->P_0023 text

  • -->P_PO_IFILE text

  • -->P_ROV_HOME_DIR text

  • -->P_ROV_CURR_DI text

  • -->P_CALL text

  • -->P_FUNCTION text

  • -->P_0029 text

  • -->P_IMPORTING text

  • -->P_FILE_NAME text

  • -->P_= text

  • -->P_PO_IFILE text

----


FORM get_current_directory USING _fieldname

_filename

homedir

currdir.

IF _fieldname <> space.

PERFORM dunp_value_read USING _fieldname _filename.

ENDIF.

IF _filename = space.

currdir = homedir.

ELSE.

rov-work_dir = _filename.

rov-fdpos = STRLEN( rov-work_dir ).

DO.

IF rov-fdpos = 0.

EXIT.

ENDIF.

rov-fdpos = rov-fdpos - 1.

ASSIGN rov-work_dir+rov-fdpos(1) TO <rov_p>.

IF <rov_p> = rov-delchar.

<rov_p> = space.

EXIT.

ELSE.

<rov_p> = space.

ENDIF.

ENDDO.

currdir = rov-work_dir.

ENDIF.

ENDFORM. " get_current_directory

&----


*& Form get_filename-of-server

&----


  • text

----


  • -->P_ITAB_FILENAME text

  • -->P_ROV_CURR_DIR text

  • -->P_ROV_GEN_NAME text

----


FORM get_filename-of-server TABLES nametab STRUCTURE itabfilename

USING _dirname _genname.

CALL 'C_DIR_READ_FINISH' " just to be sure

ID 'ERRNO' FIELD rov-errno

ID 'ERRMSG' FIELD rov-errmsg.

CALL 'C_DIR_READ_START' ID 'DIR' FIELD _dirname

ID 'FILE' FIELD _genname

ID 'ERRNO' FIELD rov-errno

ID 'ERRMSG' FIELD rov-errmsg.

IF sy-subrc <> 0.

EXIT.

ENDIF.

REFRESH _nametab.

DO.

CLEAR _nametab.

CALL 'C_DIR_READ_NEXT' ID 'TYPE' FIELD _nametab-type

ID 'NAME' FIELD _nametab-name

ID 'LEN' FIELD _nametab-len

ID 'OWNER' FIELD _nametab-owner

ID 'MTIME' FIELD _nametab-mtime

ID 'MODE' FIELD _nametab-mode

ID 'ERRNO' FIELD _nametab-errno

ID 'ERRMSG' FIELD _nametab-errmsg.

_nametab-dirname = _dirname.

MOVE sy-subrc TO _nametab-subrc.

CASE sy-subrc.

WHEN 0.

IF _nametab-name+0(1) = '.'.

ELSE.

APPEND _nametab.

ENDIF.

WHEN 1.

EXIT.

WHEN OTHERS. " SY-SUBRC >= 2

EXIT.

ENDCASE.

ENDDO.

CALL 'C_DIR_READ_FINISH' " just to be sure

ID 'ERRNO' FIELD rov-errno

ID 'ERRMSG' FIELD rov-errmsg.

ENDFORM. " get_filename-of-server

&----


*& Form help_values_get_with_table_ext

&----


  • text

----


  • -->P_ITAB_FILENAME text

  • -->P_ROV_CURR_DIR text

  • -->P_PO_IFILE text

----


FORM help_values_get_with_table_ext TABLES _filename

STRUCTURE itab_filename

USING _currdir

_selfile.

TYPES: BEGIN OF f4typ_head_struc,

tabname LIKE help_info-tabname,

fieldname LIKE help_info-fieldname,

head_text LIKE shstruc-keyword,

END OF f4typ_head_struc.

DATA itab_fields LIKE TABLE OF help_value WITH HEADER LINE.

DATA itab_selvals LIKE TABLE OF help_vtab WITH HEADER LINE.

DATA itab_values LIKE TABLE OF rlgrap-filename WITH HEADER LINE.

DATA itab_header TYPE TABLE OF f4typ_head_struc WITH HEADER LINE.

REFRESH itab_fields.

REFRESH itab_selvals.

REFRESH itab_values.

REFRESH itab_header.

itab_fields-tabname = 'PS0192'.

itab_fields-fieldname = 'BAA01'.

itab_fields-selectflag = ' '.

APPEND itab_fields.

itab_fields-tabname = 'RLGRAP'.

itab_fields-fieldname = 'FILENAME'.

itab_fields-selectflag = 'X'.

APPEND itab_fields.

LOOP AT _filename.

itab_values = itab_filename-type.

APPEND itab_values.

itab_values = itab_filename-name.

APPEND itab_values.

ENDLOOP.

CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE_EXT'

EXPORTING

  • CUCOL = 0

  • CUROW = 0

  • DISPLAY = ' '

  • FIELDNAME = ' '

  • TABNAME = ' '

  • TITLE_IN_VALUES_LIST = ' '

  • SHOW_ALL_VALUES_AT_FIRST_TIME = ' '

  • USE_USER_SHRINKING = ' '

titel = _currdir

  • NO_SCROLL = ' '

  • NO_CONVERSION = ' '

  • NO_MARKING_OF_CHECKVALUE = ' '

IMPORTING

index = rov-index

select_value = rov-selvalue

TABLES

fields = itab_fields

select_values = itab_selvals

valuetab = itab_values

  • HEADING_TABLE =

EXCEPTIONS

field_not_in_ddic = 1

more_then_one_selectfield = 2

no_selectfield = 3

OTHERS = 4.

IF sy-subrc = 0.

CLEAR itab_filename.

READ TABLE itab_filename INDEX rov-index.

IF itab_filename-type+0(3) = 'dir'.

CONCATENATE _currdir rov-delchar rov-selvalue rov-delchar

INTO _selfile.

ELSE.

CONCATENATE _currdir rov-delchar rov-selvalue INTO _selfile.

ENDIF.

ENDIF.

ENDFORM. " help_values_get_with_table_ext

Best regards,

Prashant

Read only

Former Member
0 Likes
1,438

Hi,

The function module works very well.

The point is that while debugging the entire fields of the internal table does not show up.

Check this... <b>The filenames are stored in the NAME field of the internal table.</b>

DATA it_filelist LIKE TABLE OF RSFILLST WITH HEADER LINE.

CALL FUNCTION 'SUBST_GET_FILE_LIST'
EXPORTING
DIRNAME = 'usrsap'
FILENM = '*'
PATTERN = ''
TABLES
FILE_LIST = IT_FILELIST
.

LOOP AT it_filelist.
 WRITE : / it_filelist-DIRNAME, it_filelist-NAME.
ENDLOOP.

Read only

vinod_gunaware2
Active Contributor
0 Likes
1,438

USe function module

<b>RZL_READ_DIR_LOCAL</b>

<b>SUBST_GET_FILE_LIST</b> Return table with file list for the given directory (pattern allowed)

<b>F4_DXFILENAME_TOPRECURSION</b> Popup to select one <b>file from the given application server directory

TH_SERVER_LIST</b> Returns list of application servers.

<b>EPS_GET_DIRECTORY_LISTING</b> – Lists filenames from the application server .

this will be definately useful.

regards

vinod

Read only

0 Likes
1,438

Thanks Experts for your help.

Vinod thanks a lot for providing names of function modules.

Regards,

Irfan

Read only

vinod_gunaware2
Active Contributor
0 Likes
1,438

Please reward Point if it is useful.

Regards

Vinod