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: 

Function Module

Former Member
0 Kudos
175

I have need of a function module that finds a file in directory on file system of BW.

thanks

5 REPLIES 5

former_member188685
Active Contributor
0 Kudos
94

Hi Welcome to SDN,

I don't think there is a FM for that.

regards

vijay

0 Kudos
94

hi,

Welcome...

I guess You have to know where is the file, so use the GUI_UPLOAD to upload it.

Alexandre Nogueira.

Former Member
0 Kudos
94

Antonio Brudaglio

Welcome to SDN !!!!!

Take a look at the Class CL_GUI_FRONTEND_SERVICES.

Some of the methods are useful would be :

1. GET_SYSTEM_DIRECTORY

2. GUI_UPLOAD

3. DIRECTORY_LIST_FILES

Thanks,

Kam

Former Member
0 Kudos
94

Hi,

I don't know if exit a standard FM, but you can build one custom that uses external command (un a linux enviorement you could use th command whereis). For external opereting system command you can see the SM69 transaction.

I hope it can help you.

Bye

enzo

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos
94

I assume you want a server side directory listing. I had to write my own class to do this. It uses Kernel calls (use with caution!) to read the server directory.

method get_directory_listing.
*@78QImporting@	I_DIR_NAME	TYPE CSEQUENCE	
*@78QImporting@	I_FILE_MASK	TYPE EPSFILNAM  DEFAULT SPACE	File Name
*@79QExporting@	E_DIR_LIST	TYPE T_ZES_EPSFILI	

  data: begin of file,
        dirname(175) type c, "name of directory. (possibly truncated.)
        name(175)    type c, " name of entry. (possibly truncated.)
        type(10)     type c, " type of entry.
        len(16)      type p, " length in bytes.
        owner(8)     type c, " owner of the entry.
        mtime(6)     type p, " last modification date, seconds since 1970
        mode(9)      type c, " like "rwx-r-x--x": protection mode.
        errno(3)     type c,
        errmsg(40)   type c,
      end of file.
  field-symbols: <wa_dir_list> like line of e_dir_list.
  data: error_counter type i.

* get directory listing
  call 'C_DIR_READ_FINISH'                  " just to be sure
        id 'ERRNO'  field file-errno
        id 'ERRMSG' field file-errmsg.

  call 'C_DIR_READ_START'
        id 'DIR'    field i_dir_name
        id 'FILE'   field i_file_mask
        id 'ERRNO'  field file-errno
        id 'ERRMSG' field file-errmsg.
*  if sy-subrc <> 0.
*    raise read_directory_failed.
*  endif.

  do.
    clear file.
    call 'C_DIR_READ_NEXT'
          id 'TYPE'   field file-type
          id 'NAME'   field file-name
          id 'LEN'    field file-len
          id 'OWNER'  field file-owner
          id 'MTIME'  field file-mtime
          id 'MODE'   field file-mode
          id 'ERRNO'  field file-errno
          id 'ERRMSG' field file-errmsg.

    if sy-subrc = 0.
      append initial line to e_dir_list assigning <wa_dir_list>.
      <wa_dir_list>-size = file-len.
      <wa_dir_list>-name = file-name.
      if file-type(1) = 'f' or              " regular file
         file-type(1) = 'F' or
         file-type(1) = 'd'.
*       add 1 to file_counter.
        if file-type(1) = 'f'.
          <wa_dir_list>-rc   = 0.
        else.
          <wa_dir_list>-rc = 1.
        endif.
      endif.
    elseif sy-subrc = 1.
      exit.
    else.
      if error_counter > 1000.
        call 'C_DIR_READ_FINISH'
              id 'ERRNO'  field file-errno
              id 'ERRMSG' field file-errmsg.
*        raise too_many_read_errors.
        exit.
      endif.
      add 1 to error_counter.
    endif.
  enddo.


endmethod.

My exporting parameter is a table type for a structure that I copied from EPSFILI. I made the filename and filesize parameters larger:

Original:

Filename type CHAR 40

Filesize type INT4

Copy:

Filename type CHAR 175

Filesize type FLTP Len 16 Decimal 16