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: 

How to read file name from application server?

Former Member
0 Kudos

Hi experts,

i need to read one file from presentation server but i don't know the name of the file.So i expect from folder that i'm reading only one file.So how i can take the name of the file in my Abap program?

Is anyone have an idea?

Thanks in advance!

9 REPLIES 9

SuhaSaha
Advisor
Advisor
0 Kudos

>

> Hi experts,

>

> i need to read one file from presentation server but i don't know the name of the file.So i expect from folder that i'm reading only one file.So how i can take the name of the file in my Abap program?

>

> Is anyone have an idea?

> Thanks in advance!

What do you mean by that? Will your folder always have only one file ?? Do you have the folder name atleast

If YES, then use the method FILE_OPEN_DIALOG of the class CL_GUI_FRONTEND_SERVICES. If this suits your requirement you can search in SDN for details.

BTW are you looking for Application server or Presentation server ?

BR,

Suhas

former_member212005
Active Contributor
0 Kudos

Hey....you have written contradicting statements...

The subject line mentions from Application server...while the post mentions presentation server.

Anyways...if you are reading the file from application server...and you know the path...then this is how you will get the list of files inside the directory..



* Get a directory listing from the inbox
  SELECT SINGLE *
    FROM sxpgcotabe
         WHERE name     = 'LIST_DB2DUMP'
           AND opsystem = sy-opsys.

  IF sy-subrc <> 0.
    SELECT SINGLE *
      FROM sxpgcotabe
           WHERE name     = 'LIST_DB2DUMP'
             AND opsystem = 'UNIX'.
    IF sy-subrc <> 0.
      MESSAGE e000 WITH 'External operating system command '
                        'LIST_DB2DUMP not found'.
    ENDIF.
  ENDIF.

  sxpgcotabe-parameters = p_filepath. "the file path of directory

  CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
       EXPORTING
            commandname                   = sxpgcotabe-name
            additional_parameters         = sxpgcotabe-parameters
            operatingsystem               = sxpgcotabe-opsystem
       TABLES
            exec_protocol                 = lt_execprot
       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.
  IF sy-subrc <> 0.
    MESSAGE e000 WITH text-e01 p_filepath.  "Directory failed
  ENDIF.

* Loop round the directory list, split each line up into a line table
* and get the last data for each line, should be the filename
* Then build the dirlist.

  REFRESH t_dirlist.
  LOOP AT lt_execprot.
    REFRESH t_dirline.
    SPLIT lt_execprot-message AT space INTO TABLE t_dirline.
    DESCRIBE TABLE t_dirline LINES w_nolines.
    READ TABLE t_dirline INDEX w_nolines.
    MOVE t_dirline-data TO t_dirlist-filename.
    APPEND t_dirlist.
  ENDLOOP.

0 Kudos

Hello Vin,

FYI, you have a FM for this: EPS_GET_DIRECTORY_LISTING. Why write code for it )

BR,

Suhas

0 Kudos

Suhas....thanks for providing this answer....was not aware of it..

Former Member
0 Kudos

HI,

check this FM F4_dxfilename_toprecursion to get F4 help for the application file

Former Member
0 Kudos

Try something like following

DATA : LV_COUNT TYPE I,
       LT_FILES TYPE TABLE OF CHAR1024.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
  EXPORTING
    DIRECTORY                   = 'C:\TEMP'
*    FILTER                      = '*.*'
*    FILES_ONLY                  =
*    DIRECTORIES_ONLY            =
  CHANGING
    FILE_TABLE                  = LT_FILES
    COUNT                       = LV_COUNT
  EXCEPTIONS
    CNTL_ERROR                  = 1
    DIRECTORY_LIST_FILES_FAILED = 2
    WRONG_PARAMETER             = 3
    ERROR_NO_GUI                = 4
    NOT_SUPPORTED_BY_GUI        = 5
    OTHERS                      = 6
        .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

0 Kudos

Thanks guys,

now my requirements changed have read the file from FTP NON SAP SERVER.Of cource i first use FTP_CONNECT. And know the directory name. What FM can i use? The above, you are mention are working only for application server.

Any idea?

0 Kudos

Hi,

You can use the below FM to get the files from u r file directory.

EPS_GET_DIRECTORY_LISTING

export the Directory name

Regards,

0 Kudos

Hi all,

i solved the problem with FTP_Command i pass command 'dir SAP_test' and in result i received the name of the file.Thanks to all.