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

efficient code to search for a file with suffix

Former Member
0 Likes
650

Hi all,

I have a report that can find a file and transfer it to an interface. The file suffix prevously has only two digits i.e filename22. Now it has four digits i.e filename9876

The actual code was using a code like this to find and transfer the file filename55:

sufx = 0

do x time

search file with filenamesufx that content data

if found give back the filename

else

sufx = sufx + 1

enddo

It will run 55 times before giving back the file name because the file exist in the sap directory.

Now I would like to implement it efficiently for 4 digits suffix. I would like to save the last suffix found each time to make the next search faster.

What are the efficient ways to save the suffix for the next search (in a database table i.e)? What are the efficients ways to write the new loop?

The suffix are now in the range : 0000 to 9999.

How can I implement the search without running the loop 9999 time in the worst case.

Thanks for your help.

Hi all,

I have a report that can find a file and transfer it to an interface. The file suffix prevously has only two digits i.e filename22. Now it has four digits i.e filename9876

The actual code was using a code like this to find and transfer the file filename55:

sufx = 0

do x time

search file with filenamesufx that content data

if found give back the filename

else

sufx = sufx + 1

enddo

It will run 55 times before giving back the file name because the file exist in the sap directory.

Now I would like to implement it efficiently for 4 digits suffix. I would like to save the last suffix found each time to make the next search faster.

What are the efficient ways to save the suffix for the next search (in a database table i.e)? What are the efficients ways to write the new loop?

The suffix are now in the range : 0000 to 9999.

How can I implement the search without running the loop 9999 time in the worst case.

Thanks for your help.

2 REPLIES 2
Read only

arindam_m
Active Contributor
0 Likes
580

Hi,

You can use the FM EPS2_GET_DIRECTORY_LISTING with the with the input parameter FILE_MASK used ( say passing to filter value as filename* ) the get file list from the SAP directory. Then you can loop through the internal table that will have all the files with names starting with filename.

The pattern for the FM is:

CALL FUNCTION 'EPS2_GET_DIRECTORY_LISTING' "

  EXPORTING

    iv_dir_name =               " eps2filnam

*   file_mask = SPACE           " epsf-epsfilnam

  IMPORTING

    dir_name =                  " epsf-epsdirnam

    file_counter =              " epsf-epsfilsiz

    error_counter =             " epsf-epsfilsiz

  TABLES

    dir_list =                  " eps2fili

  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    "

    .  "

Cheers,

Arindam

Read only

SujeetMishra
Active Contributor
0 Likes
580

Hi,

Use Function Module RZL_READ_DIR to check your all files at particular directory and Sort it, you will get latest file at top.

Regards,

Sujeet