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

Read a file from folder

Former Member
0 Likes
842

i need to get a file from application server folder with date validation.

how do i get the file from foder with fname, size and date.

8 REPLIES 8
Read only

Former Member
0 Likes
815

Hi

Use CG3Y or CG3Z transaction.

Regards

Ravi

Read only

Former Member
0 Likes
815

Hi

Plz elaborate on your requirment.

Regards

Raj

Read only

0 Likes
815

i need to develop the interface based on input file, it will be placed on application server foder with different file names, so i need to read that folder and look for specific file *.txt copy into my ITAB.

Read only

0 Likes
815

This is Rich example ..... try this......

report zrich_0001 .
 
data: begin of itab occurs 0,
      rec(1000) type c,
      end of itab.
data: wa(1000) type c.
 
data: p_file type localfile.
data: ifile type table of  salfldir with header line.
 
parameters: p_path type salfile-longname
                    default '/usr/sap/TST/DVEBMGS01/data/'.
 
 
call function 'RZL_READ_DIR_LOCAL'
     exporting
          name           = p_path
     tables
          file_tbl       = ifile
     exceptions
          argument_error = 1
          not_found      = 2
          others         = 3.
 
loop at ifile.
  format hotspot on.
  write:/ ifile-name.
  hide ifile-name.
  format hotspot off.
endloop.
 
 
at line-selection.
 
  concatenate p_path ifile-name into p_file.
 
  clear itab.  refresh itab.
  open dataset p_file for input in text mode.
  if sy-subrc = 0.
    do.
      read dataset p_file into wa.
      if sy-subrc <> 0.
        exit.
      endif.
      itab-rec = wa.
      append itab.
    enddo.
  endif.
  close dataset p_file.
 
  loop at itab.
    write:/ itab.
  endloop.
 

Read only

0 Likes
815

thanks, it doesn't have the date stamp.

how can i get one with fname, size & date

Read only

0 Likes
815

why don't try in SXDB Transaction ?

GOTO SXDB -> object 0010 -> enter -> click on copy ->here copy from and copy to

Read only

Former Member
0 Likes
814

If the file is given as input in the selection screen u can use Dataset. (Open dataset). If there is no selection screen then the filename will be the same with te date and time stamp.

EX : Prgram name : ztest

file name : ztest_11062007_050311 (Program name _ date _time)

This will be the format so u can use dataset and u can build the filename in your program and use it.

Reward if helpful.

Regards,

Umasankar.

Read only

ferry_lianto
Active Contributor
0 Likes
814

Hi,

Please try this.


    DATA: FILETAB TYPE TABLE OF FILE_INFO,
          FILEREC TYPE FILE_INFO,
          COUNT TYPE i,
          FZISE TYPE i.

    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
      EXPORTING
        DIRECTORY                   = '<Yourfilename>'
        FILTER                      = ''
        FILES_ONLY                  = 'X'
      CHANGING
        FILE_TABLE                  = FILETAB
        COUNT                       = COUNT
      EXCEPTIONS
        CNTL_ERROR                  = 1
        DIRECTORY_LIST_FILES_FAILED = 2
        WRONG_PARAMETER             = 3
        ERROR_NO_GUI                = 4
        others                      = 5.
 
    IF SY-SUBRC <> 0.
      RAISE CNTL_ERROR.
    ENDIF.
 
    IF COUNT = 0.
*     Does not exist
      RESULT = ABAP_FALSE.
      FSIZE  = 0.
    ELSE.
*     Does exist
      RESULT = ABAP_TRUE.
      READ FILETAB INDEX 1 INTO FILEREC.
      FSIZE = FILEREC-FILELENGTH.
    ENDIF.

Regards,

Ferry Lianto