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

How to upload a text file into an internal table?

Hi gurus

i need help regarding unploading a text file ,then reading its contents into an internal table .

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 May 16, 2008 at 11:51 AM

    Hello.

    Use FM GUI_UPLOAD.

    TYPES: BEGIN OF ty_tab,
             lines TYPE string,
           END OF ty_tab.
    
    DATA: itab TYPE STANDARD TABLE OF ty_tab.
    
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                = 'C:\Documents and Settings\valter\Desktop\nota1084207.txt'
        filetype                = 'ASC'
      TABLES
        data_tab                = itab
      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.
    

    Reward if usefull,

    Best regards.

    Valter Oliveira.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 16, 2008 at 08:58 PM

    Hi Sayanto,

    There are two servers where you can import text files: from the presentation server (that's what Valter told you; GUI_UPLOAD) and from the application server.

    Application Server:

    For importing text files into an internal table you can use the following pseudo coding"

    DATA: itab type table itab_type,
            wa_struct type itab_type.
    
    OPEN DATASET <full filepath on the appl-server> for INPUT.
    WHILE SY-SUBRC = 0.  
      READ DATASET <full filepath on ...> INTO wa_struct.
           APPEND wa_struct INTO itab.
    ENDWHILE.
    CLOSE DATASET <full filepath ....>.

    Hope this helps,

    Heinz

    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.