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: 

How to upload a text file into an internal table?

Former Member
0 Kudos

Hi gurus

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

2 REPLIES 2

valter_oliveira
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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