Skip to Content
author's profile photo Former Member
Former Member

how to work with files in folders on Application/Presentation Server

Hi,

I am working on interface program in which files are populated in folders in application/presentation server in the format 'ABCsy-datumsy-uzeit.txt'(e.g.ABC20051022161450.txt,ABC20051022161455.txt ) in directory c:\temp.

I want to sort all these files and read in sorted manner.

can anybody help me out in this.

waiting for reply.

thanks & regards,

Nitin

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 22, 2005 at 11:23 AM

    Hi

    You can use SUBST_GET_FILE_LIST to know which files are in a folder for Application Server and method DIRECTORY_LIST_FILES for Presentation server.

    These routines return the result of search in internal table you can sort how you need.

    Max

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 22, 2005 at 11:27 AM

    Hi,

    This logic will work for files on presentation server,

    DATA: l_count TYPE i,

    l_filename TYPE string,

    t_files TYPE string OCCURS 0 WITH HEADER LINE,

    BEGIN OF t_files_sorted OCCURS 0,

    file_prefix(3),

    file_date LIKE sy-datum,

    file_time LIKE sy-uzeit,

    file_extension(4),

    END OF t_files_sorted,

    t_text TYPE TABLE OF w3html.

    CALL METHOD cl_gui_frontend_services=>directory_list_files

    EXPORTING

    directory = 'C:\Temp'

    FILTER = '*.txt'

    files_only = 'X'

    • DIRECTORIES_ONLY =

    CHANGING

    file_table = t_files[]

    count = l_count

    EXCEPTIONS

    cntl_error = 1

    directory_list_files_failed = 2

    wrong_parameter = 3

    error_no_gui = 4

    OTHERS = 5.

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    LOOP AT t_files.

    t_files_sorted = t_files.

    APPEND t_files_sorted.

    ENDLOOP.

    SORT t_files_sorted BY file_date file_time.

    LOOP AT t_files_sorted.

    CONCATENATE 'C:\Temp\' t_files_sorted INTO l_filename.

    CALL METHOD cl_gui_frontend_services=>gui_upload

    EXPORTING

    filename = l_filename

    • FILETYPE = 'ASC'

    • HAS_FIELD_SEPARATOR = SPACE

    • HEADER_LENGTH = 0

    • IMPORTING

    • FILELENGTH =

    • HEADER =

    changing

    data_tab = t_text[]

    EXCEPTIONS

    FILE_OPEN_ERROR = 1

    FILE_READ_ERROR = 2

    NO_BATCH = 3

    GUI_REFUSE_FILETRANSFER = 4

    INVALID_TYPE = 5

    NO_AUTHORITY = 6

    UNKNOWN_ERROR = 7

    BAD_DATA_FORMAT = 8

    HEADER_NOT_ALLOWED = 9

    SEPARATOR_NOT_ALLOWED = 10

    HEADER_TOO_LONG = 11

    UNKNOWN_DP_ERROR = 12

    ACCESS_DENIED = 13

    DP_OUT_OF_MEMORY = 14

    DISK_FULL = 15

    DP_TIMEOUT = 16

    others = 17.

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    *****Your processing here..

    ENDLOOP.

    Also, use the FM that MAX has if you have to work with files on application server by replacing code in the above logic at appropriate places, like replace

    cl_gui_frontend_services=>directory_list_files

    with the corresponding fm

    and replace cl_gui_frontend_services=>gui_upload

    with OPEN DATASET...

    CLOSE DATASET...

    logic.

    Hope this helps..

    Sri

    Message was edited by: Srikanth Pinnamaneni

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.