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: 

Find directory from directory parameter.

Former Member
0 Kudos

Hello all,

My current requirement is to find the directory from the directory parameter.

Using AL11 we are able to see the logical path name (directory parameter), eg ZINT, and the directory path /your/path/here/int.

I would expect to find a function module that can perform this, but I am having some difficulty finding it. I have found many that will give me the file from a file path, but I do not want the file or the entire file path. My requirement is to find the first bit of the directory.

If anyone knows of a thread, link, documentation, of function module I can check out to find the solution please let me know.

Thanks in advance.

Regards,

C

1 ACCEPTED SOLUTION

former_member156446
Active Contributor
0 Kudos

check this FM might help you.

CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = ' '
filemask = ' '
IMPORTING
serverfile = p_afile
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.

10 REPLIES 10

Former Member
0 Kudos

Did you try FM FILE_GET_NAME?

This is te FM Documentation:


FU FILE_GET_NAME
____________________________________________________
Short Text
Assign the Physical File Name Using a Logical File Name


Functionality
R/3 applications run on various platforms with various file systems. This function module enables you to 
use platform-independent logical file names in your application programs.

Based on definitions maintained in customizing tables for platform-independent file names, the function 
module converts a logical file name to the corresponding physical file name and path for the hardware platform concerned.
For this conversion to work for different platforms, the definition of a logical file name must include a logical
 file path, which in turn is converted to different physical file paths, depending on the particular platform. 
The platform-specific file name returned by the function module is composed of the physical file path for the current platform and the physical file name associated with the logical file name. Placeholders in physical file and path names are substituted at runtime by the corresponding current values.

Example

logical file name: MONTHLY_SALES_FILE 
physical file name: VALUES<PARAM_1> 
logical path: SALES_DATA_PATH 
  physical path (UNIX): /usr/<SYSID>/<FILENAME> 
  physical path (Windows): C:\SALES\<FILENAME> 


Example 1
Get file name for UNIX platform
(current system: K11)

CALL                                                                                FUNCTION                                                                                'FILE_GET_NAME'
   EXPORTING
      LOGICAL_FILENAME = 'MONTHLY_SALES_FILE'
   IMPORTING
      FILE_NAME = FILE
      FILE_FORMAT = FORMAT.

Result:
FILE = /usr/K11/VALUES
FORMAT = WK1

Example 2
Get file name for UNIX platform, passing a parameter
(current system: K11)

CALL                                                                                FUNCTION                                                                                'FILE_GET_NAME'
   EXPORTING
      LOGICAL_FILENAME = 'MONTHLY_SALES_FILE'
      PARAMETER_1 = '_TST'
   IMPORTING
      FILE_NAME = FILE
      FILE_FORMAT = FORMAT.

Result:
FILE = /usr/K11/VALUES_TST
FORMAT = WK1

Example 3
Get file name for WINDOWS platform, with file name extension

CALL                                                                                FUNCTION                                                                                'FILE_GET_NAME'
   EXPORTING
      LOGICAL_FILENAME = 'MONTHLY_SALES_FILE'
      WITH_FILE_EXTENSION = 'X'
   IMPORTING
      FILE_NAME = FILE
      FILE_FORMAT = FORMAT.

Result:
FILE = C:\SALES\VALUES.WK1
FORMAT = WK1

Notes
All definitions needed for the platform-independent assignment of file names are maintained client-
independently with transaction FILE. Logical file names (but not logical file paths) can also be defined 
specifically for the current client with transaction SF01. Transaction SF07 generates a list of current definitions.

The following concepts are used in the platform-independent assignment of file names:

Logical file name
A descriptive name for a file which is associated with these values:
physical file name
file format
logical file path.
If no logical file path is specified, the function module returns the physical file name only; placeholders are
 substituted by current values.
Physical file name
The physical file name may contain placeholders.
Logical file path
A descriptive name for a path which is associated with these values:
syntax groups (groups of operating systems)
physical file paths.
Physical file path
The physical file path is defined for a particular syntax group. It must contain the reserved word <FILENAME> as a placeholder for the file name. It may also contain other placeholders.
Operating system
Presentation server and application server can run under different operating systems. The current value for the application server can be obtained from the system field SY-OPSYS, the value for the presentation server by calling function module WS_QUERY.
Both operating systems must be defined and assigned to a syntax group.
Syntax group
Group of operating systems with a common syntax for file and path names (e.g. HP-UX and SINIX).

Placeholder
Reserved words, set in angle brackets, which can be included in physical file and path names (e.g. 
<DATE>, <FILENAME>). You can find information on possible reserved words in the online help (F1 help)
 for the fields physical file name and physical file path when maintaining platform-independent file names 
with transaction FILE.
If the logical path associated with a logical file name does not specify a physical path for the current operating system (syntax group), the path stored in the profile parameter DIR_GLOBAL of the current 
system is used for generating a complete platform-specific file name.

Parameters
CLIENT
LOGICAL_FILENAME
OPERATING_SYSTEM
PARAMETER_1
PARAMETER_2
PARAMETER_3
USE_PRESENTATION_SERVER
WITH_FILE_EXTENSION
USE_BUFFER
ELEMINATE_BLANKS
EMERGENCY_FLAG
FILE_FORMAT
FILE_NAME

Exceptions
FILE_NOT_FOUND

Function Group
SFIL

0 Kudos

Asking him to read documentation is enough dont paste the whole documentation here.

you cant paste materials or any other thing if its not your own

former_member156446
Active Contributor
0 Kudos

check this FM might help you.

CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = ' '
filemask = ' '
IMPORTING
serverfile = p_afile
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.

Former Member
0 Kudos

hi

check this FM may help you..

SO_SPLIT_FILNAME_PATH .

it will give file name and path seperately.

Former Member
0 Kudos

Aparna,

Thank you for your suggestion however I have already checked out that FM. It requires a file name. My requirement will not have a file name. I will create my own file name which will be added to the end of the actual path. I need to find the logical path from directory parameter.

Jay,

I have tried to use this function module, however gathering the logical path will be done in the background during the program. The user will not have a choice in path. Thank you for your advice.

If my requirements are unclear, please let me know and I will be glad to clarify.

Regards,

C

Former Member
0 Kudos

Venu,

In our system we do no have this function module. I did a search on Split_filename and I found a few function modules. They all required the long path or the actual path. I will need some functionality found with AL11.

We have the Directory Parameter of 'ZINT' ( I will have this at runtime). I need to translate this into the corresponding logical path: /your/path/here as you would see in AL11.

Thank you for your response.

Regards,

C

Former Member
0 Kudos

Thanks everyone for your help.

I was able to derive a solution from using table PATH and using File_get_name. The parameter the user was using is not found when using the FM, however this function module could work with some adjustments.

Regards,

C

Former Member
0 Kudos

7 years later...same problem as you. How did you solve it?

Regards!

I've used USER_DIR table and worked!

0 Kudos

Hi Cullen,

I believe you can use the Function modules from CL_FRONTEND_SERVICES. They offer many methods for directories and file manipulation and file processing as well.

Also, there' a good article here about working with files. You might want to visit this one:

Working with files - ABAP Development - SCN Wiki

There's a heading title here that says getting the list of files in directory. It might work the same for finding the directories given a file location parameter.

Hope this helps.

Thanks and warmest regards,

Ryann Ong