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: 

Read Directory from AL11

former_member364077
Participant
0 Kudos

Hello Experts,

How to check whether files are existing or not from the perticular directory in AL11.

Thanks in advance.

Indra

1 ACCEPTED SOLUTION

GauthamV
Active Contributor
0 Kudos

Use the FM EPS_GET_DIRECTORY_LISTING to get list of files in directory and

then check if your file exists or not.

8 REPLIES 8

GauthamV
Active Contributor
0 Kudos

Use the FM EPS_GET_DIRECTORY_LISTING to get list of files in directory and

then check if your file exists or not.

birendra_chatterjee
Active Participant
0 Kudos

Use 'EPS2_GET_DIRECTORY_LISTING' This f.m. gives you provision to provide a larger path.

Regards,

Birendra

Private_Member_1084
Active Contributor
0 Kudos

You can simple use

OPEN DATASET <your filename> FOR INPUT .... 

If the file doesn't exist, you will get SY-SUBRC = 8. [http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_ACCESS.htm#!ABAP_ALTERNATIVE_1@1@]

Cheers,

Suhas

PS: If the file does not exist you cannot read it

0 Kudos

Simple and efficient way to check an existing file. Thanks ..

shrikanth_rathod
Explorer
0 Kudos

Hi,

Try the belwo FM

c_cmd TYPE sxpglogcmd VALUE 'WWI_GET_DIR'

V_PARAM = directory Path

c_sys TYPE syopsys VALUE 'ANYOS'.

CALL FUNCTION 'SXPG_COMMAND_EXECUTE'

EXPORTING

commandname = c_cmd

additional_parameters = v_param

operatingsystem = c_sys

stdout = c_x

stderr = c_x

terminationwait = c_x

TABLES

exec_protocol = i_command

EXCEPTIONS

no_permission = 1

command_not_found = 2

parameters_too_long = 3

security_risk = 4

wrong_check_call_interface = 5

program_start_error = 6

program_termination_error = 7

x_error = 8

parameter_expected = 9

too_many_parameters = 10

illegal_command = 11

wrong_asynchronous_parameters = 12

cant_enq_tbtco_entry = 13

jobcount_generation_error = 14

OTHERS = 15.

The Internal table I_COMMAND will be having all the files which is uploaded to the folder.

DELETE i_command INDEX 1. " Always delete the first record from I_Command

Below Code Represents how to take the Exact File name from the I_COMMAND internal table

Store the File names into one Internal Table.

LOOP AT i_command INTO wa_command.

v_strlen = wa_command-length - 1.

CLEAR: v_check.

WHILE v_check IS INITIAL.

v_char = wa_command-message+v_strlen.

IF v_char = space.

v_check = c_x.

ELSE.

v_strlen = v_strlen - 1.

CONCATENATE v_char wa_filename-file INTO wa_filename-file.

ENDIF.

IF v_strlen LE 0.

v_check = c_x.

ENDIF.

ENDWHILE.

APPEND wa_filename TO i_filename.

CLEAR wa_filename.

ENDLOOP.

Inoder to read the Contents of the File

Loop at the File Name Internal Table

Before Reading file Concatenate <Directory Path> and File name then use

OPEN DATASET

READ DATASET

and CLOSE DATA .

Regards,

Shrikanth

0 Kudos

Thanks for the inputs.

I have solved my issue with them.

Thread closed.

Indra

former_member364077
Participant
0 Kudos

Thanks for all inputs

andrea_olivieri
Contributor
0 Kudos

Hi,

try the function module RZL_READ_DIR.

Then check in the results FILE_TBL[ ] if your file exists or not.

Very very simple.

Regards,

Andrea