Application Development 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: 

Downloading file from Application Sever

Former Member
0 Kudos

Hi Gurus,

I have a requirement in which I have to execute my program once in every 15 minutes which will check if there are any files present in application server. Is so I have to retreive the files to SAP from Application server.

Now I have couple of issues in doing so.

1. How to find the number of files present in that directory?

2. How to retreive more than 1 file at a time from the directory.

Its bit urgent.

Cheers,

Naveen

NOTE: Points will be awarded to every useful answer.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

try this:

CONSTANTS: CMD_LS(50) VALUE 'ls -al /tmp/sap/'. "Your directory.

*

DATA: BEGIN OF ITAB_LS OCCURS 0,

LINE(200),

END OF ITAB_LS.

*

CALL 'SYSTEM'

ID 'COMMAND' FIELD CMD_LS

ID 'TAB' FIELD ITAB_LS-SYS.

and look into table ITAB_LS.

Regards, Dieter

9 REPLIES 9

valter_oliveira
Active Contributor
0 Kudos

Hello.

Check this simple code:


DATA: BEGIN OF t_processar OCCURS 0,
        line(136) TYPE c,
        ficheiro(40),
        path(100),
      END OF t_processar,
DATA: l_cmd_unix LIKE w_cmd_unix.
DATA: numb_files TYPE i.

CLEAR: l_cmd_unix, w_cmd_unix.
CONCATENATE '/usr/sap/' sy-sysid '/interfaces/in/'  INTO l_cmd_unix.

CONCATENATE 'ls' l_cmd_unix INTO w_cmd_unix SEPARATED BY space.
CALL 'SYSTEM' ID 'COMMAND' FIELD w_cmd_unix
              ID 'TAB'     FIELD t_processar-*sys*.

DESCRIBE TABLE t_processar LINES numb_files. "number of files

* Processa os vários ficheiros
LOOP AT t_processar.
  CLEAR t_linhas. REFRESH t_linhas.

  CONCATENATE '/usr/sap/' sy-sysid '/interfaces/in/' t_processar-line
           INTO t_processar-line.

  OPEN DATASET t_processar-line FOR INPUT IN TEXT MODE.
  CHECK sy-subrc EQ 0.
  DO.
*Leitura do ficheiro para tabela interna t_linhas
    READ DATASET t_processar-line INTO t_linhas.
    IF sy-subrc EQ 0.
      APPEND t_linhas.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.

  CLOSE DATASET t_processar-line.

ENDLOOP.

Regards.

Valter Oliveira.

Former Member
0 Kudos

Hi,

You can retrive the files in application server directory by using the FM

RZL_READ_DIR_LOCAL.

Once you get the list of files you can use OPEN DATASET and read them.

Hope this helps.

PARAMETER: p_fdir            type pfeflnamel DEFAULT '/usr/sap/tmp'.

data: begin of it_filedir occurs 10.
        include structure salfldir.
data: end of it_filedir.


************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
* Get Current Directory Listing for OUT Dir
  call function 'RZL_READ_DIR_LOCAL'
       exporting
            name     = p_fdir
       tables
            file_tbl = it_filedir.

* List of files are contained within table it_filedir
  loop at it_filedir.
    write: / it_filedir-NAME.
  endloop.

0 Kudos

Hi,

Thanks for the reply.

The problem is solved.

Points awarded...

Cheers,

Naveen

Former Member
0 Kudos

Hi,

try this:

CONSTANTS: CMD_LS(50) VALUE 'ls -al /tmp/sap/'. "Your directory.

*

DATA: BEGIN OF ITAB_LS OCCURS 0,

LINE(200),

END OF ITAB_LS.

*

CALL 'SYSTEM'

ID 'COMMAND' FIELD CMD_LS

ID 'TAB' FIELD ITAB_LS-SYS.

and look into table ITAB_LS.

Regards, Dieter

Former Member
0 Kudos

hi

good

1 st -Use the function module SUBST_GET_FILE_LIST to get all the files under a specific directory in the application server.

2 nd-Use read file statement to read the particular file from the applicaion server.

thanks

mrutyun^

Former Member
0 Kudos

Hi,

You can use FM EPS_GET_DIRECTORY_LISTING to get all the files from application server in given directory.Then looping that table you can get data from file using open data set

IF pa_adir+lw_len(1) NE c_fhash .

CONCATENATE pa_adir c_fhash INTO pa_adir.

ENDIF. " IF pa_adir+lw_len(1) NE c_fhash

CLEAR w_dir.

w_dir = pa_adir.

lw_dirname = pa_adir.

REFRESH:

t_files_app.

  • Getting all files in that directory with filter

CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'

EXPORTING

dir_name = lw_dirname

file_mask = w_filter

TABLES

dir_list = t_files_app

EXCEPTIONS

invalid_eps_subdir = 1

sapgparam_failed = 2

build_directory_failed = 3

no_authorization = 4

read_directory_failed = 5

too_many_read_errors = 6

empty_directory_list = 7

OTHERS = 8.

Here lw_dirname is directory name

and w_filter is filter for file types like *.txt

and you will get all files in t-files_app

Reward points if help ful

former_member705122
Active Contributor
0 Kudos

Hi,

Check this link:

Regards

Adil

Former Member
0 Kudos

Hi

With the use of OPEN DATASET... CLOSEDATASET , you can download file from application server.

Regards

Nikunj Shah

Former Member
0 Kudos

The problem is solved.