Latest File in AL11

In AL11, we have many files for the perticular interface in a perticular dedicated folder/directory.
Out of these many files, I have to read the one that is latest.
Any idea how do get the file name of the latest file?
Thanks
Edited by: Pranu Pranu on Jan 26, 2011 5:12 AM

There is to method you can use.
1. Use the OS kernal functions.
get directory listing
CALL 'C_DIR_READ_FINISH' " just to be sure
ID 'ERRNO' FIELD files-errno
ID 'ERRMSG' FIELD files-errmsg.
CALL 'C_DIR_READ_START'
ID 'DIR' FIELD dir_nam
ID 'FILE' FIELD ''
ID 'ERRNO' FIELD files-errno
ID 'ERRMSG' FIELD files-errmsg.
IF sy-subrc 0.
*RAISE read_directory_failed.
ENDIF.
REFRESH files.
CLEAR file_counter.
CLEAR error_counter.
DO. <<<<<<<<<<<<<<----
Start Of reading a directory sequentially
CLEAR files.
files-dirname = dir_nam.
CALL 'C_DIR_READ_NEXT'
ID 'TYPE' FIELD files-type
ID 'NAME' FIELD files-name
ID 'LEN' FIELD files-len
ID 'OWNER' FIELD files-owner
ID 'MTIME' FIELD files-mtime
ID 'MODE' FIELD files-mode
ID 'ERRNO' FIELD files-errno
ID 'ERRMSG' FIELD files-errmsg.
IF sy-subrc = 0.
*Here You can match the creation time of the file by comparing it with others
IF <File is old then process with the next file>.
CONTINUE.
ELSEIF ( files-type(1) 'd' ) AND " <<<<----
D indicated directories
( files-type(1) 'D' ).
ADD 1 TO file_counter.
files-subrc = '0'.
PERFORM p6_to_date_time_tz(rstr0400)
USING
files-mtime
files-mod_time
files-mod_date.
APPEND files.
ENDIF.
ELSEIF sy-subrc = 1.
EXIT.
ELSE.
IF error_counter > 1000.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD files-errno
ID 'ERRMSG' FIELD files-errmsg.
RAISE too_many_read_errors.
ENDIF.
ADD 1 TO error_counter.
files-subrc = '18'.
PERFORM p6_to_date_time_tz(rstr0400)
USING
files-mtime
files-mod_time
files-mod_date.
APPEND files.
ENDIF.
ENDDO.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD files-errno
ID 'ERRMSG' FIELD files-errmsg.
IF file_counter > 0.
SORT files BY name ASCENDING.
ELSE.
*RAISE empty_directory_list.
ENDIF.
And Finally You can use the FILES table to get the latest file name.
2. Another method go with function module EPS_GET_DIRECTORY_LISTING and collect all file in output table and use some file information function module like EPS_GET_FILE_ATTRIBUTES or following kernal method to compare every file creation date and time and get the latest file out of that.
CALL 'C_FILE_ATTRIBUTES'
          ID 'NAME'   FIELD file_path
          ID 'TYPE'   FIELD file-type
          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.
Cheers
Dhirendra Pandit

Similar Messages

  • Picking file in AL11

    hiii
    i have several file in AL11 in the following mail.
    FILE_V1
    file_v2
    file_v3
    etc....
    i have to pick up the latest version please advise how to do that in al11

    Hi,
    transaction code FDTA

  • How to Select the Latest file from Application Server?

    Dear All,
    I am working on object, which had requirement to Pick the file from application server.
    The Application server contain the files in ‘/temp/sms/’ directory. The files are having the name Like ‘smsqry_yyyymmddhhmmss.txt’ and I have to Pick the Latest file (Base on file name for eg. 'smsqry_20060713102333’) from that all and after getting the file I have to delete the file from application server.
    So How to do this.
    Regards

    hi,
    look function group EPSF-
    esp. fm EPS_GET_DIRECTORY_LISTING
    if you're looking fo OS-date and time
    look here:Re: How do I convert MTIME to date and time?
    A.
    Message was edited by: Andreas Mann

  • How to delete a  file from AL11??????

    Hi Friends,
    how can i delete a file from AL11 directory....
    i have found FM's like EPS_DELETE_FILE, EDI_PORT_DELETE_FILE and some more from SAP system but those are not deleting the files....
    let me know if i can write a program for this and if yes then guide me for writing the same....
    Thanks,
    Nagesh.

    reference:http://saplab.blogspot.com/2007/10/sample-abap-program-to-delete-file-from.html
    REPORT ZDELETE.
    Delete a file on the application server.
    PARAMETERS: P_DIR LIKE RLGRAP-FILENAME
    DEFAULT '/usr/sap/trans/', *it will delete files from this dir
    P_FILE1 LIKE RLGRAP-FILENAME.
    DATA: P_FILE(128).
    DATA: W_ANS.
    START-OF-SELECTION.
    CONCATENATE P_DIR P_FILE1 INTO P_FILE.
    check file exists
    OPEN DATASET P_FILE FOR INPUT.
    IF SY-SUBRC NE 0.
    MESSAGE E899(BD) WITH P_FILE 'does not exist'.
    EXIT.
    ELSE.
    CALL FUNCTION 'POPUP_CONTINUE_YES_NO'
    EXPORTING
    DEFAULTOPTION = 'N'
    TEXTLINE1 = P_DIR
    TEXTLINE2 = P_FILE1
    TITEL = 'ARE YOU SURE YOU WANT TO DELETE'
    START_COLUMN = 25
    START_ROW = 6
    IMPORTING
    ANSWER = W_ANS
    EXCEPTIONS
    OTHERS = 1.
    ENDIF.
    CLOSE DATASET P_FILE.
    CHECK W_ANS = 'J'.
    delete
    DELETE DATASET P_FILE.
    IF SY-SUBRC NE 0.
    MESSAGE E899(BD) WITH 'Invalid file name' P_FILE.
    ELSE.
    CLOSE DATASET P_FILE.
    MESSAGE I899(BD) WITH P_DIR P_FILE1 'DELETED'.
    ENDIF

  • How to get Latest file from a Folder

    Hi,
          I would like to access latest file in a folder based upon time stamp in the file properties. Can anybody help me in this regard.
    Regards,
    Visuman 

    Hey,
    I hope this solves your problem.
    If you have any questions, just ask them
    Greetz, Bart
    P.S. the solution is in the attachment
    Attachments:
    file.jpg ‏91 KB

  • Getting the latest file from application server

    Hi,
    I have to retrieve the latest file posted in R/3 from the application server to ISU which conatins the file name with timestamp.
    regards
    Mac

    Hi,
    so use fm EPS_GET_DIRECTORY_LISTING
    and sort corresp. table DIR_LIST
    A.

  • How to download a file from AL11 inot Excel format without collapse the col

    Hi,
    Please suggest how to download a file from AL11 to Excel sheet.currenlty all field are merging into single column.I writing this file via using DATASET.
    Regards
    Ricky

    Hi,
       Try this code,
    ==============================================
    TYPES : BEGIN OF ty_emp,
              empno(2) TYPE c,
              empid(10) TYPE c,
              empname(3) TYPE c,
            END OF ty_emp.
    DATA : it_emp TYPE TABLE OF ty_emp,
            wa_emp TYPE ty_emp.
    DATA : pbk TYPE string.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    PARAMETERS : p_file TYPE rlgrap-filename.
    PARAMETERS : p_asfile TYPE rlgrap-filename.
    SELECTION-SCREEN END OF BLOCK b1.
    pbk = p_file.
    OPEN DATASET p_asfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.
      DO.
        READ DATASET p_asfile INTO wa_emp.
        IF sy-subrc <> 0.
          EXIT.
        ENDIF.
        APPEND wa_emp TO it_emp.
      ENDDO.
    CLOSE DATASET p_asfile.
    Filling the already created file with download PS radiobutton
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
      BIN_FILESIZE                  =
          filename                      = pbk
      FILETYPE                      = 'ASC'
         append                        = 'X'
         write_field_separator         = ' '
      HEADER                        = '00'
      TRUNC_TRAILING_BLANKS         = ' '
      WRITE_LF                      = 'X'
      COL_SELECT                    = ' '
      COL_SELECT_MASK               = ' '
      DAT_MODE                      = ' '
    IMPORTING
      FILELENGTH                    =
        TABLES
          data_tab                      = it_emp
    EXCEPTIONS
      FILE_WRITE_ERROR              = 1
      NO_BATCH                      = 2
      GUI_REFUSE_FILETRANSFER       = 3
      INVALID_TYPE                  = 4
      NO_AUTHORITY                  = 5
      UNKNOWN_ERROR                 = 6
      HEADER_NOT_ALLOWED            = 7
      SEPARATOR_NOT_ALLOWED         = 8
      FILESIZE_NOT_ALLOWED          = 9
      HEADER_TOO_LONG               = 10
      DP_ERROR_CREATE               = 11
      DP_ERROR_SEND                 = 12
      DP_ERROR_WRITE                = 13
      UNKNOWN_DP_ERROR              = 14
      ACCESS_DENIED                 = 15
      DP_OUT_OF_MEMORY              = 16
      DISK_FULL                     = 17
      DP_TIMEOUT                    = 18
      FILE_NOT_FOUND                = 19
      DATAPROVIDER_EXCEPTION        = 20
      CONTROL_FLUSH_ERROR           = 21
      OTHERS                        = 22
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ==============================================
    Regards,
    Krrishna

  • How to generate a empty file in AL11 using ABAP and unix command

    Hi Experts,
    when load infopackage triggers it will search file from AL11 if file is available it will get loaded successfully.  When there is no file in AL11 error while opening file (orgin A) and the load will fail.  At this level i have to write a abap code using unix command to generate a empty file.
    Is there any way to achieve the above requirement.
    Thanks
    Vara

    Hi,
    If i get your requirement properly then you want to create a blank file if there is no file on the application server so that your infopackage does not fail, am i correct.
    If this is your requirement then this can be easily done if you use process chain to load the file via infopackage. Follow the following steps:
    1. Add a ABAP program before the infopackage and check if the file is present on the server or not. Use a simple ABAP statement OPEN DATASET <FNAME>. Check the SY-SUBRC after this statement if it is not 0 then it means that the file does not exist on the application server.
    2. Once you have established that the file is not present create a flat file using a code similar to the below one
    OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE
                          MESSAGE D_MSG_TEXT.
    IF SY-SUBRC NE 0.
      WRITE: 'File cannot be opened. Reason:', D_MSG_TEXT.
      EXIT.
    ENDIF.
    * Transferring Data
    LOOP AT INT_table.
      TRANSFER INT_table-field1 TO FILENAME.
    ENDLOOP.
    * Closing the File
    CLOSE DATASET FILENAME.
    3. Add your infopackage step after this ABAP program in your process chain.
    I hope this helps.
    Best Regards,
    Kush Kashyap

  • Issuse in Uploading a .CSV file from AL11 to Database table.

    Hi All,
    I have a .CSV file (UTF-8 format) which contains Chinese Characters.
    I uploaded the file to AL11 and it shows that all teh data is correct in AL11.
    Now i am using a program to Read file from AL11 and update a ztable but some of the characters are
    modified and some are getting saved as junk characters.
    Kindly let me know what can be done.
    Regards,
    Jose

    Jose,
    The issue is pretty much clear. Ask the IT team to change the regional settings for languages. Normally we don't have
    access to Korean, Traditional chinese....etc.
    You might be getting characters/symbols as ?? ##. Go ahead and change the regional setting.
    This will solve your issue.

  • Download file from AL11 into CSV to load MD into BPC

    Hi All
    I have an issue in downloading file from AL11 which is in the form of CSV.
    1) I have exported the masterdata for Costcenter using a Open hub.
    2) The file is residing at the app server AL11 in the form of CSV.
    3) I want to down load the file into CSV and upload that file into BPC NW for my costcenter diemension.
    When i am downloading the file from AL11 , the total records are merged into one row, i cannot download same as it is available in AL11.
    I have followed the HOW TO GUIED : HOW TO AUTOMATE MD LOADING IN BPC nw.
    I m unable to get the file properly on to my PC.
    could you please help me .
    AK

    You should open your file in AL11, then clicking 'List' then 'Save' you'll be able to download your file. There will be some header lines indeed.
    You'd better use an open hub with your local client as destination if you need the file.

  • Double quotes missing in CSV file but exist in text file from AL11

    Hi I am sending a file to AL11 with one of the fields having double quotes Like "field value" . When i download into Text file  i am seeing the quotes but not when download as CSV file from Al11. Any SAP notes for this . If i add  multiple quotes ' """" ' to have in csv I am seeing more quotes in text file which is not accepted . Please reply if anyone worked on this before . Thanks Kamesh

    The CSV file also has the quotes (check in notepad), but when opened in MS Excel, Excel has a feature to ignore double quotes and consider the comma inside the quotes as part of field, not as a field separator.

  • How to XI pick latest file from folder.

    hi,
    I have one folder in that i got almost10 files one by one with some different time period..
    My requirement is Every time XI Will pick latest file from  that folder With out deleting previous file.
    how it is possible.
    Any special configuration in  file adapter may be it is sender or receiver.
    Please Clarify.
    Thanks

    Hi Venkata shiva ,
    agree with Michael
    you can have some java or scripts  that will help you may be change the name of the latest file and that be picked up by your adapter, asuming you have changed settings of your adapter to pick the file with this name.
    Significance : -  this will also not posts your file at the receiver multiple times.
    Thanks and Regards,
    Vishal
    Message was edited by:
            vishal kharat

  • Variable to get Latest File Name

    Hi All,
    I have a requirement of loading a Flat file(.csv) into an Oracle table.
    There will a file coming in on regular basis which will be the source to Oracle table.
    The name is like DATA_<date>.csv, i need to pick the latest file which has arrived and use it as the source.
    I have created a datastore and used a variable name *(#var_FILE_NAME)* in the resource name field, so that i can refresh the variable and then execute the interface to pick the filename refreshed by the variable.
    But what query should i write in the variable to get the latest file name.?
    Thanks in advance!
    Warm Regards,
    VBV

    Hi Guru/Ananth,
    Thanks for you reply.
    @Ananth: I have already checked this blog, but in this blog they have mentioned about the usage of Declare Variable. But in my case I'm going to refresh the Variable.
    @Guru: This query will work in case if i get the file daily. But in case if i get file on different days, ineed to pick the latest file. hope you get the requirement.
    Thanks in advance!
    Warm Regards,
    VBV

  • How to upload  and download a files into AL11 directory in ABAP

    Hi,
                   How to upload  and download a files into AL11 directory in ABAP
    thanks
    Moderator message: please search for available information/documentation.
    Edited by: Thomas Zloch on Mar 21, 2011 9:18 AM

    You should try one of these forums for an answer to your question:
    http://swforum.sun.com/jive/forum.jspa?forumID=116
    http://community.java.net/netbeans
    http://linux.java.net

  • How to download a CSV file in AL11 to XL into diferent tabs  ?

    Hello All,
            I have a file in AL11 of type CSV.
    When I download this file into XLS from AL11 all the data is downloaded under one tab itself.
    But I want the data in separate columns wherever there is a comma in the line.
    How can I do this ?
    Regards,
    Deepu.K
    null

    Hello manoj,
           Thanks for ur reply.
    But I forgot to mention that I want this functionality when I directly download from AL11..not thru the Program.
    i.e my job is to place the files in the AL11.
    The end users will check the file name across the appropriate folder and then use the Download option in the AL11 Transaction to download it.
    Now when they see the file in AL11 it is with comma separated.
    When they download it ..it's still comma separated and in only one tab.
    I want to avoid this ..
    Is it possible ?
    Regards,
    Deepu.K

Maybe you are looking for