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: 

Get file names in a directory but in background.

Former Member
0 Kudos

Hi Friends,

My desire is get file names in a network directory, not on application server directory. How can I get the given network directory files names?

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

you can read the files with the following command:

CONCATENATE 'ls ' p_path INTO ux_com SEPARATED BY space.

CALL 'SYSTEM' ID 'COMMAND' FIELD ux_com

ID 'TAB' FIELD i_files-sys.

p_path contains your Unix filepath.

Kind regards Henner

8 REPLIES 8

Former Member
0 Kudos

HI ,

Use FTP.

REPORT ZFTPSAP LINE-SIZE 132.

DATA: BEGIN OF MTAB_DATA OCCURS 0,

LINE(132) TYPE C,

END OF MTAB_DATA.

DATA: MC_PASSWORD(20) TYPE C,

MI_KEY TYPE I VALUE 26101957,

MI_PWD_LEN TYPE I,

MI_HANDLE TYPE I.

START-OF-SELECTION.

*-- Your SAP-UNIX FTP password (case sensitive)

MC_PASSWORD = 'password'.

DESCRIBE FIELD MC_PASSWORD LENGTH MI_PWD_LEN.

*-- FTP_CONNECT requires an encrypted password to work

CALL 'AB_RFC_X_SCRAMBLE_STRING'

ID 'SOURCE' FIELD MC_PASSWORD ID 'KEY' FIELD MI_KEY

ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD MC_PASSWORD

ID 'DSTLEN' FIELD MI_PWD_LEN.

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

*-- Your SAP-UNIX FTP user name (case sensitive)

USER = 'userid'

PASSWORD = MC_PASSWORD

*-- Your SAP-UNIX server host name (case sensitive)

HOST = 'unix-host'

RFC_DESTINATION = 'SAPFTP'

IMPORTING

HANDLE = MI_HANDLE

EXCEPTIONS

NOT_CONNECTED = 1

OTHERS = 2.

CHECK SY-SUBRC = 0.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

HANDLE = MI_HANDLE

COMMAND = '<b>dir</b>'

TABLES

DATA = MTAB_DATA

EXCEPTIONS

TCPIP_ERROR = 1

COMMAND_ERROR = 2

DATA_ERROR = 3

OTHERS = 4.

IF SY-SUBRC = 0.

LOOP AT MTAB_DATA.

WRITE: / MTAB_DATA.

ENDLOOP.

ELSE.

  • do some error checking.

WRITE: / 'Error in FTP Command'.

ENDIF.

CALL FUNCTION 'FTP_DISCONNECT'

EXPORTING

HANDLE = MI_HANDLE

EXCEPTIONS

OTHERS = 1.

Check this link also

0 Kudos

the only way to get file names in a network directory in background using ftp? I need other solutions.

thanks.

0 Kudos

Also,

using FTP functions, how the logic is applying? Our directory such as
comp1\FILES is not an ftp file. When using ftp functions as

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

*-- Your SAP-UNIX FTP user name (case sensitive)

USER = 'userid'

PASSWORD = MC_PASSWORD

*-- Your SAP-UNIX server host name (case sensitive)

HOST = 'unix-host'

will the host equal
comp1\FILES? And, also what is the meaning your sap-unix ftp user name? I am new in sap-ftp connections. Can you explain a bit more, listing any directory files using ftp functions without real ftp? And the last, our application server is not unix, it is nt based. Is it possible again to use ftp functions?

Thanks for your helps.

Former Member
0 Kudos

Hi,

The function module for getting the list of file names in a directory is

TMP_GUI_DIRECTORY_LIST_FILES.

As far as i know, you can not run this function module in background as in background mode, it will not get the handle of the local file system from where you need to read the contents. The SAP GUI should be running to execute this function module.

Regards,

Ramanath.

varma_narayana
Active Contributor
0 Kudos

Hi...

Check out the Methods in the Class CL_GUI_FRONTEND_SERVICES

<b>Reward if Helpful</b>

Former Member
0 Kudos

Hi,

you can read the files with the following command:

CONCATENATE 'ls ' p_path INTO ux_com SEPARATED BY space.

CALL 'SYSTEM' ID 'COMMAND' FIELD ux_com

ID 'TAB' FIELD i_files-sys.

p_path contains your Unix filepath.

Kind regards Henner

0 Kudos

Hi Henner,

can you explain i_files-sys

I need a runnable code.

Thanks.

0 Kudos

Hi Nkara,

right now i'm not havin access to the system, i can check monday afternoon.

But try this.

i_files is just an internal table with one field for the filename.

Use SE11 and search a rollname like path, file.

Take a field that has length 128 (usually is long enough, if not take one with 256 ) and is type char.

Then you code:

data: begin of i_files occurs 0,

filename type <the_fieldname_you_found_char_128>.

data: end of i_files.

p_path is your pathname usually 128 is also long enough.

parameters:p_path(128) deault '/your_paht/'.

This should work, the -sys is just for the called C-routine relevant.

Use it the way i suggested.

Kind regards

Henner

<b>Reward if helpful</b>